I've been trying for days to connect my application to a remote server with the NET::SSH gem without success. The issue seems to originate from the fact I need to use a private key file to authenticate the login.
require 'net/ssh'
def SSH(host, user, psw, keys, cmd)
Net::SSH.start( host,
user,
:password => psw,
:host_key => "ssh-rsa",
:encryption => ["blowfish-cbc","aes256-cbc"],
:keys => keys,
:verbose => :debug,
:auth_methods => ["publickey","password"]
) do|ssh|
@result = ssh.exec!(cmd)
puts @result
end
return @result
end
The debug output gives me the error:
Could not load private key file `C:/path_to_key/key.ppk': ArgumentError (Could not parse PKey)
I've seen many examples of this error with No start line
appended however have not found anything to suggest workarounds to this. I've even uninstalled and reinstalled the NET::SSH gem.
I have no problem connecting through puTTY/WinSCP with the same credentials so I'm sure there are no remote authentication issues.
Any help appreciated
The issue for me was the format of the private key. For some (still unexplained) reason Ruby didn't like the .ppk
extension.
To get round it
ssh-keygen -t rsa
(or dsa if you want more secure format) on the remote box to generate public/private key pair. Give it a folder in which to put both keys.
Add public key to ~/.ssh/authorized_keys file
Move private key to local machine with WinSCP and use it as key or key_data for NET::SSH