ssh远程服务器登录脚本 [英] ssh remote server login script

查看:137
本文介绍了ssh远程服务器登录脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我正在尝试使用"pty"和amp ;;将红宝石脚本写入登录SSH远程服务器. 期望"红宝石库.并尝试使用该脚本在远程系统内部创建新的Rails应用.

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.

任何人都可以告诉我.如何使用ruby库登录到远程服务器?

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

推荐答案

您应该看一下Net::SSH的一些示例,它基本上打开了一个连接并为您提供了一个块,可以执行所需的任何命令,例如:

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

(摘录自此处)

我什么都没做,但是你明白了.有了这种结构,您就可以在远程服务器上运行任何您喜欢的程序并解析其输出.由于您可能对公钥授权感兴趣,因此应该查看

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.

这篇关于ssh远程服务器登录脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆