如何处理“伪终端不会被分配,因为stdin不是终端". [英] How to deal with "Pseudo-terminal will not be allocated because stdin is not a terminal."

查看:38
本文介绍了如何处理“伪终端不会被分配,因为stdin不是终端".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ssh -t remotehost vim /tmp/x.txt

我知道我可以运行上述命令.

I know that I can run a command like the above.

但我希望能够在远程机器上运行任何本地 bash 代码.出于这个原因,我想调用远程bash -s",以便可以处理任何本地 bash 代码.

But I would like to be able to run any local bash code in a remote machine. For this reason, I'd like to call the remote 'bash -s' so that can process any local bash code.

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

然而,上面的例子显示伪终端不会被分配,因为标准输入不是终端."有什么方法可以让 ssh 通过 stdin 获取本地 bash 代码并通过远程bash -s"运行它?谢谢.

However, the above example shows "Pseudo-terminal will not be allocated because stdin is not a terminal." Is there any way to let ssh take local bash code via stdin and run it via the remote 'bash -s'? Thanks.

推荐答案

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

您收到伪终端将不会被分配..."消息,因为您正在使用单个 -t 选项运行 ssh,当 ssh 进程的标准输入是不是 TTY.在这种情况下,ssh 会专门打印该消息.文档 -t 说:

You're getting the "Pseudo-terminal will not be allocated..." message because you're running ssh with a single -t option, when the standard input to the ssh process isn't a TTY. ssh prints that message specifically in this case. The documentation for -t says:

-t
强制伪终端分配.这可用于在远程机器上执行任意基于屏幕的程序,这非常有用,例如在实现菜单服务时.多个 -t 选项强制 tty 分配,即使 ssh 没有本地 tty.

-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:

The -t command-line option is related to the ssh configuration option RequestTTY:

RequestTTY
指定是否为会话请求伪 tty.参数可以是以下之一:no(从不请求 TTY)、yes(当标准输入是 TTY 时总是请求 TTY)、force(总是请求 TTY)或 auto(打开登录会话时请求 TTY).此选项反映了 ssh(1) 的 -t 和 -T 标志.

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".

A single -t is equivalent to "RequestTTY yes", while two of them is equivalent to "RequestTTY force".

如果您希望远程命令使用 TTY 运行,请指定 -t 两次:

If you want your remote command(s) to run with a TTY, then specify -t twice:

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

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

ssh will allocate a TTY for the remote system and it won't print that message.

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

If the command(s) being run on the remote system don't require a TTY, you can leave the -t option out:

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

这篇关于如何处理“伪终端不会被分配,因为stdin不是终端".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆