0

I am trying to execute couple of commands on remote server and as authentication method, I am using public keys.

Public keys are configured properly on server and I can connect to it without system prompting me for password like this:

ssh root@example.com

So this is what I do in my code:

Net::SSH.start(host, user, :keys=>["~/.ssh/id_rsa","~/.ssh/id_rsa.pub"]) do |ssh|
  ssh.exec "service nginx reload"
end

On local machine, everything works properly, when on production server, I get an error.

Net::SSH::AuthenticationFailed: Authentication failed for user root@example.com

I did some Googling and I had already tried to fallback to net_ssh 2.7.0, yet no luck, same issue. I also tried to replace relative path to absolute, in my case /root/.ssh/... I tried adding an option

:auth_methods => ['publickey']

yet still, no luck.

I am also certain that the keys reside in correct paths.

EDIT 1

Worth noting that this works perfectly well when run in production rails console.

EDIT 2

Symptoms here are similar with ones in this question: Net::SSH works from production rails console, AuthenticationFailed from production webapp with exception that my app runs from root and there shouldn't be permission issues because of that.

EDIT 3

I had temporary fallen back to password auth that works fine but I'd really like to use key auth instead.

Any help on this issue is much appreciated.

Community
  • 1
  • 1
Vitali
  • 690
  • 9
  • 29
  • you're running as root? (this is a really bad idea) when it goes owned they get whole box. can you look at the logs on the far end. also :keys is only for the private keys, I don't think you need the public key in there as it isn't used for for connecting, and that could be messing it up – Doon Jun 27 '14 at 12:53
  • I tried removing keys option entirely, same effect, doesn't work. on auth.log there is nothing related to an attempt of this server to connect to another. – Vitali Jun 27 '14 at 13:44

0 Answers0