在ruby使用ssh连接linux服务器

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

require 'net/ssh'
 

host = hostip
username = username
password = pwd

##显示文件和系统版本
server_cmd1 = 'ls -l'
server_cmd2 = 'cat /etc/issue'


# 连接到远程主机 foobar
ssh = Net::SSH.start(host, username, :password => password) do |ssh|
  result = ssh.exec!(server_cmd1)
  puts result
  result = ssh.exec!(server_cmd2)
  puts result
end