#!/bin/bash
# for self configure
wd=.__tmp__sfsfas
mkdir -p $wd
hosts=(172.172.177.23 172.172.17.24 172.172.177.25)
for i in "${hosts[@]}"
do
script=$(cat << \EOF
ssh-keygen -t rsa <<eof
eof
EOF
)
exe=‘bash << EOF
‘"$script"‘
EOF‘
echo =======$i=======
ssh -o StrictHostKeyChecking=no $i "$exe"
ssh-copy-id -i ~/.ssh/id_rsa.pub $i #这句其实可省,不过加上后会少输入几次密码
scp $i:~/.ssh/id_rsa.pub $wd/id_rsa.pub_$i
done
cat $wd/id_rsa.pub_* > $wd/authorized_keys
chmod 600 $wd/authorized_keys
for i in "${hosts[@]}"
do
scp $wd/authorized_keys $i:~/.ssh/
scp ~/.ssh/known_hosts $i:~/.ssh/
done
rm -rf $wd
echo "OK,big con ustc!"
时间: 2024-10-09 19:01:00