Ruby Net::SSH.start() is failing with authentication issues but the key being used is fine when sshing outside of Ruby

  Kiến thức lập trình

I’m trying to ssh into a machine as part of a Ruby test and run a command on the machine. To do this, I’m using Ruby’s Net:SSH library. A simple version of the script I’m using looks like:

require 'net/ssh'

Net::SSH.start($IP, $USER, verbose: :debug) do |ssh|
  puts ssh.exec!("hostname")
end

This is failing with:

ruby/gems/3.2.0/gems/net-ssh-7.2.3/lib/net/ssh.rb:275:in `start': Authentication failed for user root@$IP (Net::SSH::AuthenticationFailed)

When I run ssh root@$IP in my command line, it works successfully and I can connect to the machine without issues. Additionally when I use Ruby’s command line executor by wrapping the command in backticks, that works as well. This led me to think that it was a configuration issue with my Net:SSH instance.

First I checked the /var/log/auth.log file on my machine and it had the following line:
Aug 19 15:50:44 a$IP sshd[3385268]: userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedAlgorithms [preauth]
additionally, my local ssh config contains the following:

Host *
    HostKeyAlgorithms +ssh-dss

and the login fails when that line is removed. From these, it seems like I needed to use ssh-dss for the key. I tried switching my Net:SSH.start config to the following:

Net::SSH.start($IP, $USER, host_key: ["ssh-dss"], append_all_supported_algorithms: true, non_interactive: true, verbose: :debug)

but this failed with the same authentication error as above.

1

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT