01. 免互動建立秘鑰對
ssh-keygen -t rsa -f /root/.ssh/id_rsa -P ""
02. 免互動分發公鑰,可以指定使用者分發,預設是root
centos 7
yum install sshpass -y
sshpass -p123456 ssh-copy-id -i /root/.ssh/id_rsa.pub "-o StrictHostKeyChecking=no" [email protected]
centos 6
sshpass -p123456 ssh-copy-id -i /root/.ssh/id_rsa.pub "-o StrictHostKeyChecking=no [email protected]"
3.免互動批量分發公鑰腳本
#!/bin/bash
#chuangjian,key pair
rm -f /root/.ssh/id_dsa*
ssh-keygen -t dsa -f /root/.ssh/id_dsa -P "" -q
#install sshpass
yum install sshpass -y &>/dev/null
# fenfa key file
for ip in `cat /server/scripts/game_ip.txt`
do
echo "===== fenfa key to host $ip ====="
sshpass -proot密碼 ssh-copy-id -i /root/.ssh/id_dsa.pub "-o StrictHostkeyChecking=no root@$ip"
echo "============= fenfa end =================="
echo ""
done
4. 批量管理腳本
#!/bin/bash
CMD="$1"
if [ $# -ge 1 ];then
for ip in ·cat game_ip.txt·
do
echo "====== host $ip info ========"
ssh $ip $CMD
echo "======================================"
echo ""
done
else
exit
fi