0

I have the code like this:

require 'rubygems'
require 'net/ssh'

hostname = '1.2.3.4'
username = 'user' 
cmd = "ls -al"


ssh = Net::SSH.start(hostname, username)
res = ssh.exec!(cmd)
ssh.close
puts res

Here comes the error:

Authentication failed for user user@1.2.3.4 (Net::SSH::AuthenticationFailed)

How can I find the problem?

orde
  • 5,233
  • 6
  • 31
  • 33
Tim
  • 23
  • 4

2 Answers2

0

Check your ssh keys is present in both remote and local. And for the Ruby code please refer this link

ssh remote server login script

0

I'm unfamiliar with the ssh gem you're using. However, first check the simple:

  1. Is the machine your working on able to establish a ssh connection on with a working ssh server e.g. Github.

Test this by following the GitHub guide to setting up ssh for your Operating System.

  1. Is there a remote server with the IP Address 1.2.3.4 listening for a ssh connection?

  2. Which port is it listening on? The default port is 22.

Answer these questions by attempting an ssh connection between the two machines outside of Ruby, using the ssh client you used above fore question 1.

Youll likely find the issue answering these questions. If you don't, consult the documentation for the gem. I should provide instructions for all I've recommended however, I'm on mobile.

Patrick Quigley
  • 404
  • 2
  • 12