ruby 自动连ssh_Ruby Net :: SSH,SSH(安全外壳)协议

ruby 自动连ssh

SSH (or "Secure Shell") is a network protocol that allows you to exchange data with a remote host over an encrypted channel. It's most commonly used as an interactive shell with Linux and other UNIX-like systems. You may use it to log into a Web server and run a few commands to maintain your website. It can also do other things, though, such as transfer files and forward network connections.

SSH(或“安全外壳”)是一种网络协议,允许您通过加密通道与远程主机交换数据。 它最常用作Linux和其他类似UNIX的系统的交互式外壳。 您可以使用它登录Web服务器并运行一些命令来维护您的网站。 但是,它也可以做其他事情,例如传输文件和转发网络连接。

Net::SSH is a way for Ruby to interact with SSH. Using this gem, you can connect to remote hosts, run commands, examine their output, transfer files, forward network connections, and do anything you would normally do with an SSH client. This is a powerful tool to have if you frequently interact with remote Linux or UNIX-like systems.

Net :: SSHRuby与SSH交互的一种方式。 使用此gem,您可以连接到远程主机,运行命令,检查其输出,传输文件,转发网络连接,以及执行通常使用SSH客户端执行的任何操作。 如果您经常与远程Linux或类似UNIX的系统进行交互,则这是一个强大的工具。

安装Net :: SSH ( Installing Net::SSH )

The Net::SSH library itself is pure Ruby--it requires no other gems and doesn't need a compiler to install. However, it does rely on the OpenSSL library to do all the encryption needed. To see if OpenSSL is installed, run the following command.

Net :: SSH库本身就是纯Ruby,不需要其他gem,也不需要编译器即可安装。 但是,它确实依赖于OpenSSL库来执行所有需要的加密。 要查看是否已安装OpenSSL,请运行以下命令。

If the Ruby command above outputs an OpenSSL version, it's installed and everything should work. The Windows One-Click Installer for Ruby includes OpenSSL, as do many other Ruby distributions.

如果上面的Ruby命令输出的是OpenSSL版本,则说明已安装并且一切正常。 Ruby的Windows一键式安装程序与其他许多Ruby发行版一样都包含OpenSSL。

To install the Net::SSH library itself, install the net-ssh gem.

要安装Net :: SSH库本身,请安装net-ssh gem。

基本用法 ( Basic Usage )

The most common way to use Net::SSH is to use the Net::SSH.start method. This method takes the hostname, username and password and will either return an object representing the session or pass it to a block if given one. If you give the ​start method a block, the connection will be closed at the end of the block. Otherwise, you'll have to manually close the connection when you're finished with it.

使用Net :: SSH的最常见方法是使用Net :: SSH.start方法。 此方法采用主机名,用户名和密码,并将返回代表会话的对象,或者将其传递给块(如果已指定)。 如果你给start方法块,连接将在块的年底前关闭。 否则,您必须在完成连接后手动关闭该连接。

The following example logs into a remote host and gets the output of the ls (list files) command.

以下示例登录到远程主机,并获取ls (列表文件)命令的输出。

Within the block above, the ssh object refers to the open and authenticated connection. With this object, you can launch any number of commands, launch commands in parallel, transfer files, etc. You might also notice that the password was passed as a hash argument. This is because SSH allows for a variety of authentication schemes, and you need to tell it this is a password.

在上面的块中, ssh对象引用打开并经过身份验证的连接。 使用此对象,您可以启动任意数量的命令,并行启动命令,传输文件等。您可能还注意到,密码是作为哈希参数传递的。 这是因为SSH允许使用多种身份验证方案,因此您需要告诉它这是一个密码。

翻译自: https://www.thoughtco.com/netssh-secure-shell-protocol-2908069

ruby 自动连ssh

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值