首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Net::SSH::Connection::Channel#request_pty分配远程pty

如何使用Net::SSH::Connection::Channel#request_pty分配远程pty
EN

Stack Overflow用户
提问于 2014-06-28 18:29:41
回答 1查看 654关注 0票数 2

我正在构建一个raspberry-pi客户端管理器,其中这些客户端通过SSH反向隧道连接到服务器。为此,我使用了Sinatra frameworknet-ssh库。对于单个命令,这一点很明显,我使用了服务器端事件,将命令发送到给定的url。在该操作中,命令被推送到队列,并被异步执行,然后当数据可用时,结果被推送到事件流连接,以下是命令运行器的伪代码:

代码语言:javascript
复制
 require 'net/ssh'
 # start a separate thread avoid blocking the main thread of the server.
 Thread.start do
      sess = Net::SSH.start(HOST, USER, :password => 'pass', :port => 'port')
      # once a command is pushed to the queue on the dedecated sinatra action
      # the command get executed, once the execution ends this will start listening
      # again
    loop{
      sess.exec! (queue.pop()) do|ch, stream, data|
      #this is the server-sent events stream, here the data is pushed to the client 
      #EventSource 
      stream_event_connection << data
      end
    }
 end

对于单个命令,这是可以的,例如像'ls /root‘这样的命令。但我需要的是打开一个现场终端(Interective shell),在那里用户输入命令并获得结果,就像在真正的ssh终端上一样。虽然我可能会在远程Respberry-PI客户端上打开pty,但通过使用expect库,这将是可能的。请求pty的方法是Net::SSH::Connection::Channel#request_pty方法,但是我找不到任何关于如何使用它的示例。有什么想法吗?

EN

回答 1

Stack Overflow用户

发布于 2017-11-14 00:14:15

我相信你想要的东西可以做到:

代码语言:javascript
复制
shell = sess.shell.open(:pty => true)
...
shell.exec! queue.pop ...

希望这能有所帮助

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24465897

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档