gpt4 book ai didi

ssh - 如何处理 "Pseudo-terminal will not be allocated because stdin is not a terminal."

转载 作者:行者123 更新时间:2023-12-02 13:02:23 26 4
gpt4 key购买 nike

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

您收到“伪终端不会被分配...”消息,因为您正在使用单个 -t 选项运行 ssh,而 ssh 进程的标准输入是不是 TTY。在这种情况下,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.txt
or
ssh -t -t remotehost 'bash -s' <<< vim /tmp/x.txt

ssh 将为远程系统分配一个 TTY,并且不会打印该消息。

如果远程系统上运行的命令不需要 TTY,您可以省略 -t 选项:

ssh remotehost 'bash -s' <<< vim /tmp/x.txt

关于ssh - 如何处理 "Pseudo-terminal will not be allocated because stdin is not a terminal.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48648572/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com