![在一个命令行中通过两台服务器和一个用户进行 ssh](https://linux22.com/image/26353/%E5%9C%A8%E4%B8%80%E4%B8%AA%E5%91%BD%E4%BB%A4%E8%A1%8C%E4%B8%AD%E9%80%9A%E8%BF%87%E4%B8%A4%E5%8F%B0%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%92%8C%E4%B8%80%E4%B8%AA%E7%94%A8%E6%88%B7%E8%BF%9B%E8%A1%8C%20ssh%20.png)
可能的重复:
如何使用 ssh 通过另一台电脑连接到另一台电脑
如何在一个命令行中执行以下操作?
$ ssh 服务器一 $ su - 用户 $ ssh 服务器二
当然我不能直接ssh user@server-two
答案1
ssh server-one -t ssh user@localhost -t ssh server-two
从man ssh
:
-t Force pseudo-tty 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.
答案2
ssh -t server-one 'su - user -c "ssh server-two"'