Bash脚本SSH到服务器

问题描述 投票:0回答:1

我正在开发一个SSH到许多服务器的脚本。但是所有服务器都启用了wheel用户。因此,当我在本地计算机上运行脚本时,环境会发生变化,即我作为wheel用户进行SSH,然后我需要切换到root用户并在一个脚本中完成所有操作。请帮忙。

bash ssh
1个回答
0
投票

您可能需要这样的脚本:

#!/bin/bash

SCRIPT='
sudo -kSs <<EOF
RootPassword
#Do stuff here
EOF
'

while read pass ip; do
    sshpass -p$pass ssh -o 'StrictHostKeyChecking no' -p <port> wheel@$ip "$Script"
done <<HERE
pass1 ip1
pass2 ip2
pass3 ip3
  .    .
  .    .
  .    .
HERE
© www.soinside.com 2019 - 2024. All rights reserved.