在第二台服务器上的嵌套ssh运行命令 [英] Nested ssh run commands on 2nd server

查看:66
本文介绍了在第二台服务器上的嵌套ssh运行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只能从hostA进入hostB,并且我想在hostB上运行命令.

I can only get to hostB from hostA, and I want to run commands on hostB.

ssh -t $hostA ssh -t $hostB "

   echo 'Hello World!'

   echo 'Test!'

"

此刻,它将先连接到hostA,然后再连接hostB,脚本将暂停.当我键入退出(从hostB)后,我返回到hostA,将打印2条echo命令,然后自动从hostA退出.

At the moment, this will connect to hostA then hostB and the script will pause. As soon as i type exit (from hostB) I return to hostA, the 2 echo commands are printed and then automatically exits from hostA.

如何在hostB上运行命令?

How can I run commands on hostB?

推荐答案

使用此处文档和 sshpass 更改代码可以解决问题

Changing code as using here document and sshpass can do the trick

ssh -T user@$hostA <<EOA
sshpass -p password ssh  -T user@$hostB <<EOB
echo hello 
EOB
EOA

这篇关于在第二台服务器上的嵌套ssh运行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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