Kumar C. Kumar C. - 7 months ago 32
Ruby Question

Sending a command via ssh with a publish ssh key, with no password

I can send a command via ssh to a server with login and password like this:

Net::SSH.start("", "user_name", password: "1234") do |ssh|
res = ssh.exec!("ls")

But if I want to avoid providing a password and if I've added my public ssh key to that server, how can I get rid of the password? Should I just remove it from the function call or should I somehow let the server know that I want to be authenticated by a ssh public key?

Net::SSH.start("", "user_name", keys: ['~/.ssh/id_rsa.pub']) do |ssh|
  res = ssh.exec!("ls")

If the above won’t work for you, do:

Net::SSH.start("", "user_name", 
               keys: ['~/.ssh/id_rsa.pub'],
               # host_key: "ssh-rsa", # default value
               # encryption: "blowfish-cbc", # default value
               verbose: :debug
) do |ssh|
  res = ssh.exec!("ls")

to see what’s wrong.