批量分發祕鑰
#!/bin/bash
#前提請把公鑰默認建立完成
#例 ssh-keygen --- 一路回車
cat<<eof
********************************************
請輸入你的網段,查看可用IP地址.
例:10.0.0
請耐心等待!
*******************************************
eof
read -p "Please enter the network segment where you want to distribute the secret keys : " ip
read -s -p "Please enter your local password :" pass
for i in $ip.{1..253}
do
{
ping -c 1 $i &>/dev/null
if [ $? -ne 0 ];
then
echo $i &> /dev/null
else
echo $i > /tmp/ip.txt
#先下載 yum install sshpass
#建立祕鑰
# ssh-keygen
. /etc/init.d/functions
yum install sshpass -y *> /dev/null
for ipadd in `cat /tmp/ip.txt`
do
sshpass -p$pass ssh-copy-id -i ~/.ssh/id_rsa.pub root@$ipadd -o StrictHostKeyChecking=no &>/dev/null
if [ $? -eq 0 ]
then
action "主機 $ipadd" /bin/true
echo ""
else
action "主機 $ipadd" /bin/false
echo ""
fi
done
fi
}&
done