通过SSH运行多个命令并传递密码

时间:2017-07-12 20:51:45

标签: linux ssh

感谢您查看我的查询。

如果想通过SSH执行多个命令,通过传递端口号和密码,我该怎么做?

正常语法为ssh user@machine -p port-no command 我怎么能把密码传递给这个命令。我们没有在prod机器上安装sshpass。我看到了一个使用expect的选项。

#!/bin/bash

echo "Enter host name: "
read Linux_Machine
Linux_User=root
Linux_PW=firefighter

<<-'EOF'
spawn ssh $Linux_User@$Linux_Machine -p 2222
match_max 100000
expect "*?assword:*"
send -- "$Linux_PW\r"
send -- "\r"
interact
EOF

我应该在哪里传递命令?

0 个答案:

没有答案
相关问题