所有 linux 主机之间(包含本主机)root 用户实现密钥 ssh 认证,禁用密码认证。
1.sh
rm -rf ~/.ssh/{known_hosts,id_rsa*}
ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa
yum -y install expect tcl
for i in {1..3}
do
expect << EOF
spawn ssh-copy-id [email protected].$i
expect "yes" {send "yes\r"}
expect "password:" {send "123\r"}
expect "#" {send "exit\r"}
EOF
done
2.sh
cp /home/da/.ssh/authorized_keys /root/.ssh/
cd /etc/ssh
echo "PermitRootLogin prohibit-password" >> sshd_config
echo "PubkeyAuthentication yes" >> sshd_config
echo "PasswordAuthentication no" >> sshd_config
3.sh
for i in {1..3}
do
scp /1.sh [email protected].$i:/home/da
scp /2.sh [email protected].$i:/home/da
done