ssh remote server login script

醉酒当歌 提交于 2019-12-08 04:53:06

问题


Currently I am trying to write a ruby script to logging-in SSH Remote Server using "pty" & "expect" ruby library. and also try to create new rails app inside the remote system using that script.

Anyone can tell me. how logging-in to remote server using the ruby library ?


回答1:


You should look at some of the examples for Net::SSH, it basically opens a connection and gives you a block to execute whatever command you like, e.g.:

#!/usr/bin/env ruby
require 'rubygems'
require 'net/ssh'

HOST = '192.168.1.113'
USER = 'username'
PASS = 'password'

Net::SSH.start( HOST, USER, :password => PASS ) do|ssh|
  output = ssh.exec!('ls')
  puts output
end

(taken from here)

I haven't done anything with it, but you get the idea. Given this construct you can run whatever program you like on the remote server and parse its output. As you are probably interested in public key authorization you should have a look at the answer to this question, it will show you how to specify a key-file.



来源:https://stackoverflow.com/questions/24422886/ssh-remote-server-login-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!