#!/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
原文:https://www.cnblogs.com/Mercury-linux/p/11784277.html