Ruby Net::SSH 未定义方法 'shell'

标签 ruby ssh

我正在尝试在我的 Ruby 代码中使用 SSH 登录到远程机器,然后在我通过 SSH 登录后尝试 cd 到另一个目录。这是我的 Ruby 代码来执行此操作

require 'net/ssh'
require 'rubygems'
require 'needle'

Net::SSH.start('host', 'shui', :password => "password") do |ssh|
   output = ssh.exec!("hostname")
   shell = ssh.shell.open
   shell.pwd
   shell.cd "/svn"
   puts shell.pwd
end

当我运行我的脚本时,它给我这个错误:

testssh.rb:8:in `block in <main>': undefined method `shell' ... (NoMethodError)

我很确定我已经安装了执行此操作所需的 gem。对于如何解决这个问题,有任何的建议吗?谢谢!

最佳答案

Net:SSH v2 中没有shell 方法,生成的对象是一个 Net::SSH::Connection::Session。 .

net-ssh 扩展为您提供了您正在寻找的功能:https://github.com/mitchellh/net-ssh-shell

关于Ruby Net::SSH 未定义方法 'shell',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11942579/

相关文章:

ruby-on-rails - 将 XML 转换为数据集

ruby - 更改 ruby​​ 中的方法行为

linux - “logout”的返回值是他​​上一个命令的返回值

linux - SSH 控制台上的奇怪行为?

git - 如何确定客户端的 SSH 指纹以在 Git Hook 中使用

ssh - 连接到系统 : neovim inside tmux inside ssh

ruby - 您如何监控 sidekiq 进程?

javascript - 永远重启 Node.js

Ruby:防止 cucumber 冗余的方法?

ios - SSH 协商 : Bad SSH2_MSG_KEX_DH_GEX_REPLY or something else?