当我尝试多个命令通过其他 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/