Hi,
I need to automate the ssh connection for that i wrote the small snippet
but the error shows its not able to communicate with the remote machine
using the below code. Please provide the solution.
Note:
Telnet service is not available on the remote machine
I am able to execute the command manually using Putty
###------------
##My code:
###-----------
#!/usr/bin/ruby
require ‘rubygems’
require ‘net/ssh’
def SetSsh(command)
Net::SSH.start($ipdddr, “username”, :password => “password”) do|ssh|
result = ssh.exec!(command)
puts “result = #{result}”
end
end
Main program execution
SetSsh(“ls -l”)
##########-End of File.
Error Which i received:
C:/Ruby187/lib/ruby/gems/1.8/gems/net-ssh-2.6.1/lib/net/ssh/transport/session.rb:67:in
initialize’: No connection could be made because the target machine
actively refused it. - connect(2) (Errno::ECONNREFUSED)
from
C:/Ruby187/lib/ruby/gems/1.8/gems/net-ssh-2.6.1/lib/net/ssh/transport/session.rb:67:inopen’
from
C:/Ruby187/lib/ruby/gems/1.8/gems/net-ssh-2.6.1/lib/net/ssh/transport/session.rb:67:in
initialize’
from C:/Ruby187/lib/ruby/1.8/timeout.rb:53:intimeout’
from C:/Ruby187/lib/ruby/1.8/timeout.rb:101:in timeout’
from
C:/Ruby187/lib/ruby/gems/1.8/gems/net-ssh-2.6.1/lib/net/ssh/transport/session.rb:67:ininitialize’
from
C:/Ruby187/lib/ruby/gems/1.8/gems/net-ssh-2.6.1/lib/net/ssh.rb:186:in
new’
from
C:/Ruby187/lib/ruby/gems/1.8/gems/net-ssh-2.6.1/lib/net/ssh.rb:186:instart’
from File_name.rb:49:in `SetSsh’
from File_name.rb:338
Had the same problem, solved by changing username/password by a
variable.
How the heck is that supposed to remedy a network connection error? The
latter has nothing to do with how you provide arguments to Net::SSH.
It’s
rather which arguments you pass. The original code for example did
not
contain an assignment to $ipdddr…
And please trim your quotes.
Cheers
robert
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.