Linux 执行远程命令时出现 SSH 错误:“stdin: is not a tty”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12480284/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 14:23:25  来源:igfitidea点击:

SSH error when executing a remote command: "stdin: is not a tty"

linuxbashsshdebianremote-execution

提问by Jhonathan

I'm trying to connect to machine one with ssh and then connect to another machine two with ssh. But get this error:

我正在尝试使用 ssh 连接到一台机器,然后使用 ssh 连接到另一台机器 2。但是得到这个错误:

ssh [email protected] 'ssh [email protected]'

stdin: is not a tty

采纳答案by Ярослав Рахматуллин

When logging into a shell, the remote host assumes that the connection is done by a human user. Therefore, it is reasonable to expect that they have control over the standard inon the client. That is to say, the user is giving input on a terminal through the keyboard. If the remote host detects that the user is not human (because the input is not a terminal - tty, but another process), it may warn the user about this unexpected condition.

登录 shell 时,远程主机假定连接是由人类用户完成的。因此,期望他们能够控制客户端的标准是合理的。也就是说,用户通过键盘在终端上进行输入。如果远程主机检测到用户不是人类(因为输入不是终端 - tty,而是另一个进程),它可能会警告用户这种意外情况。



A demonstration of the discussed misbehavior and how to avoid it (man sshand look for -t for a more thorough explanation).

所讨论的不当行为以及如何避免它的演示(man ssh并寻找 -t 以获得更全面的解释)。

$ ssh -t genja.org 'ssh raptor.lan hostname\; uptime'
host: genja.lan 
raptor
 21:17:27 up 3 days, 15 min,  1 user,  load average: 0.00, 0.00, 0.00
Connection to genja.org closed.

$ ssh genja.org uptime 
host: genja.lan 
 21:17:43 up 12 days, 17:40,  1 user,  load average: 0.30, 0.08, 0.02

...and the error:

...和错误:

$ ssh  genja.org 'ssh raptor.lan hostname\; uptime'
host: genja.lan 
Permission denied (publickey,keyboard-interactive).


You may want to make a tunnel instead:

您可能想要创建一个隧道:

ssh -L 4444:raptor.lan:22 genja.org

Then, on a different terminal:

然后,在不同的终端上:

ssh -p 4444 localhost will give you a conenction straight to "raptor.lan"

Use IP addresses such as 192.168.0.11 if DNS aliases are not configured on the remote end.

如果远端未配置 DNS 别名,请使用 IP 地址,例如 192.168.0.11。