通过ssh-key手动执行
ssh-keygen -f /root/.ssh/id_rsa -t rsa -P ''
ssh-copy-id -i /root/.ssh/id_rsa.pub <host1_name>
ssh-copy-id -i /root/.ssh/id_rsa.pub <host2_name>
少节点环境使用的ssh互信脚本
#!/bin/bash
IPLIST="
192.168.213.121
192.168.213.122
192.168.213.123
192.168.213.124
192.168.213.125"
rpm -q sshpass &> /dev/null || yum -y install sshpass
[ -f /root/.ssh/id_rsa ] || ssh-keygen -f /root/.ssh/id_rsa -P ''
export SSHPASS=123456
for IP in $IPLIST;do
{ sshpass -e ssh-copy-id -o StrictHostKeyChecking=no $IP; } &
done
wait
PASS="Huawei12#$"
IP_list=(
192.168.213.121
192.168.213.122
)
rm -rf /root/.ssh/id_rsa
ssh-keygen -f /root/.ssh/id_rsa -t rsa -P ''
for i in "${IP_list[@]}";do
sshpass -p "$PASS" ssh-copy-id -i root@"$i"
done
多节点环境下使用的互信脚本
#!/bin/bash
PASS="redhat"
END="160"
NET_name="eth0"
IP="$(ip a s "$NET_name" | awk -F'[ /]+' 'NR==3{print $3}')"
Segment=${IP%.*}.
rm -rf /root/.ssh/id_rsa
[ -e /root/SCANIP.log ] && echo "" > /root/SCANIP.log || touch /root/SCANIP.log
for((i=1;i<="$END";i++));do
ping -c1 -w1 "$Segment""$i" &>/dev/null && echo "$Segment""$i" >/root/SCANIP.log &
done
#删除空行
sed -Ei "/^$/d" /root/SCANIP.log
#生成ssh_key的rsa文件
ssh-keygen -t rsa -P "" -f /root/.ssh/id_rsa
while read -r line ;do
sshpass -p "$PASS" ssh-copy-id -i root@"$line"
done</root/SCANIP.log