linux - ssh inside ssh 具有多个命令

标签 linux ssh tty

当我尝试多个命令通过其他 ssh 内的 ssh 远程执行命令时,我得到了奇怪的结果。

来自 man ssh:

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

如果我这样做

ssh -t root@host1 ssh root@host2 "cat /etc/hostname && cat /etc/hostname"

ssh -t root@host1 ssh -t root@host2 "cat /etc/hostname && cat /etc/hostname"

在这两种情况下我都得到

host1
Connection to host1 closed.
host2
Connection to host2 closed.

我想要这个结果:

host1
host1
Connection to host1 closed.
Connection to host2 closed.

我想使用 ssh 内的 ssh 在同一服务器中运行所有命令。

如果我只使用一个 ssh,它就可以工作:

ssh -t root@host1 "cat /etc/hostname && cat /etc/hostname"
host1
host1
Connection to host1 closed.

最佳答案

我可以正常工作,但我无法解释发生了什么。

ssh -t root@host1 "ssh -t root@host2 \"cat /etc/hostname ; cat /etc/hostname\""
host1
host1
Connection to host1 closed.
Connection to host2 closed.

关于linux - ssh inside ssh 具有多个命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58204884/

相关文章:

node.js - 从私有(private) Github 存储库获取 Node 依赖项时,Teamcity 不使用 SSH key

linux - Bash - 如何检查我是否在图形 session 中?

c - 将结构指针传递给函数段错误 C FREEBSD

linux - 服务器上的 Git 没有 SSH 访问权限

php - Linux 上 php 服务内存使用率高

php - Git 无法通过 ssh Deployer 克隆项目

docker - docker stdin 和 tty 标志如何在容器的封面下工作?

node.js - 什么是 TTY 以及如何在 Ubuntu 上启用它?

linux - 如何打开顶部带有特定行号的vim?

python - 在进程之间通信时,队列比管道有什么优势?