Updated at: February 23, 2017
install gem net-ssh
gem install net-ssh
directlygem install [downloaded gem file]
if you are in limited network.require 'net/ssh'
#ssh by password
Net::SSH.start('host', 'username', :password => "passwd") do |ssh|
output = ssh.exec!("hostname")
puts output
end
#ssh via identical file
Net::SSH.start('host', 'username', :keys=> "primary key file") do |ssh|
output = ssh.exec!("hostname")
puts output
end
#forward port
Net::SSH.start('gateway host', 'gateway user', :password => "gateway passwd") do |ssh|
begin
ssh.forward.local(local port,"remote host",reomte port)
ssh.loop {true}
rescue
puts 'ssh session loop ended'
end
end