
ssh -t remotehost vim /tmp/x.txt
我知道我可以运行如上所述的命令.
但我希望能够在远程计算机上运行任何本地bash代码.出于这个原因,我想调用远程’bash -s’,以便可以处理任何本地bash代码.
ssh -t remotehost 'bash -s' <<< vim /tmp/x.txt
但是,上面的例子显示“由于stdin不是终端,因此不会分配伪终端”.有没有办法让ssh通过stdin获取本地bash代码并通过远程’bash -s’运行它?谢谢.
解决方法ssh -t remotehost 'bash -s' <<< vim /tmp/x.txt
您正在获取“伪终端将不会被分配…”消息,因为当ssh进程的标准输入不是TTY时,您正在使用单个-t选项运行ssh.在这种情况下,ssh专门打印该消息. documentation for -t说:
-t
Force pseudo-terminal allocation. This can be used to execute arbitrary screen-based programs on a remote machine,which can be very useful,e.g. when implementing menu services. Multiple -t options force tty allocation,even if ssh has no local tty.
-t命令行选项与ssh配置选项RequestTTY相关:
RequestTTY
SpecifIEs whether to request a pseudo-tty for the session. The argument may be one of: no (never request a TTY),yes (always request a TTY when standard input is a TTY),force (always request a TTY) or auto (request a TTY when opening a login session). This option mirrors the -t and -T flags for ssh(1).
单个-t相当于“RequestTTY yes”,而其中两个相当于“RequestTTY force”.
如果您希望远程命令与TTY一起运行,则指定-t两次:
ssh -tt remotehost 'bash -s' <<< vim /tmp/x.txtorssh -t -t remotehost 'bash -s' <<< vim /tmp/x.txt
ssh将为远程系统分配一个TTY,它不会打印该消息.
如果在远程系统上运行的命令不需要TTY,则可以保留-t选项:
ssh remotehost 'bash -s' <<< vim /tmp/x.txt总结
以上是内存溢出为你收集整理的ssh – 如何处理“由于stdin不是终端,因此不会分配伪终端.”全部内容,希望文章能够帮你解决ssh – 如何处理“由于stdin不是终端,因此不会分配伪终端.”所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)