Matudi Matudi - 4 months ago 14
Ruby Question

Net::SSH.start with a password supplied but it still keeps asking me for it to enter it manually

I'm trying to connect to a server via ssh providing a password but it still keeps asking me for it to enter it manually when the script is executing:

session = Net::SSH.start(host, "root", password: pass) do |ssh|
result = ssh.exec!("ls -l")

end


How to fix that?

Answer

If you want to make it fail when you are not able to connect you have to add non_interactive mode on start method

:non_interactive => set to true if your app is non interactive and prefers authentication failure vs password prompt

check this code

session = Net::SSH.start(host, "root", password: pass,non_interactive: true ) do |ssh|
  result = ssh.exec!("ls -l")
end

Try to connec to with that user doing ssh by yourself, if not you have to check your ssh configuration (you may to allow to root user) check on

/etc/ssh/sshd_config

if you have this config.

PermitRootLogin yes

and then restart ssh daemon.

If it still , you may check your root pass.