From: Luc Evers Date: 2012-11-23T05:27:16+09:00 Subject: Re: Errno::ECONNREFUSED in net/ssh --047d7b6d88b2e8bc4f04cf1b4a51 Content-Type: text/plain; charset=ISO-8859-1 Hi, Had the same problem, solved by changing username/password by a variable. Example: #!/usr/bin/env ruby require 'rubygems' require 'net/ssh' host = 'x.x.x.x' user = 'user' pass = 'password' Net::SSH.start( host, user, :password => pass ) do|ssh| result = ssh.exec!('ps -ef') puts result end Luc. On Thu, Nov 22, 2012 at 1:33 PM, Sambath Kumar Moorthy wrote: > 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: > 1) Telnet service is not available on the remote machine > 2) 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 > ------------------------------ > > -- > Posted via http://www.ruby-forum.com/. > > --047d7b6d88b2e8bc4f04cf1b4a51 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi,

=A0 Had the same problem, solved by changing usernam= e/password by a variable.

=A0 Example:
<= br>

=A0#!/usr/bin/env ruby
=A0require &#= 39;rubygems'
=A0require 'net/ssh'

=A0host =3D '= ;x.x.x.x'
=A0user =3D 'user'
=A0pass =3D &#= 39;password'

=A0Net::SSH.start( host, user, :p= assword =3D> pass ) do|ssh|
=A0 =A0 result =3D ssh.exec!('ps -ef')
=A0 =A0 puts = result
=A0end


=A0 =A0Luc.=




On Thu, Nov 22, 2012 at 1:33 PM, Sambath Kumar Moorthy &l= t;lists@ruby-foru= m.com> wrote:
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:
1) Telnet service is not available on the remote machine
2) 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 =3D> "passw= ord") do|ssh|
result =3D ssh.exec!(command)
puts "result =3D #{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/sessi= on.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/sessi= on.rb:67:inopen'
from
C:/Ruby187/lib/ruby/gems/1.8/gems/net-ssh-2.6.1/lib/net/ssh/transport/sessi= on.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/sessi= on.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&= #39;
from File_name.rb:49:in `SetSsh'
from File_name.rb:338
------------------------------

--
Posted via http://= www.ruby-forum.com/.


--047d7b6d88b2e8bc4f04cf1b4a51--