从输入(sshpass?)在多个本地服务器上执行 SSH 远程 cmd exec

从输入(sshpass?)在多个本地服务器上执行 SSH 远程 cmd exec

我目前正在寻找一种解决方案,用于从包含以下格式的“用户:密码”的输入文件在多个本地服务器上执行远程命令:

jboss5:manager:192.168.1.101
database1:db01:192.168.20.6
server8:localnet:192.168.31.83
x:z:192.168.1.151
test:mynet:192.168.35.44
.... and others

我希望远程执行的一些命令:

cd $HOME; ./start_script.sh; wget 192.168.1.110/monitor.sh; chmod +x monitor.sh; ./monitor.sh

我知道有一个名为“sshpass”的实用程序,但不确定如何应用该实用程序来满足我的需求。

答案1

Yes sshpass is a good option, you can use it as below

    sshpass -p "pass_here" ssh user@ip "cd $HOME; exit" #password is provided on the command line with semi-colon separated commands

Note: you need to install sshpass before you use it, it can be install using simple command as below,

    apt-get install sshpass

相关内容