用sshpass批量实现基于key验证

[root@shnne ~]# cat ssh-pass.sh 
#!/bin/bash
#利用sshpass批量实现基于key验证
#author by Jean

DIR=`cd $(dirname $0);pwd`
FILE=$DIR/pass.txt

#生成key
ssh-keygen -f /root/.ssh/id_rsa  -P '' >/dev/null 2>&1

#验证
cat $FILE | while read line
do
        IP=`echo $line|awk '{print $1}'`
        SSHPASS=`echo $line|awk '{print $2}'`
        /usr/bin/sshpass -p "$SSHPASS" ssh-copy-id -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa.pub root@${IP} -p 22  > /dev/null 2>&1
        if [ $? -eq 0 ];then
                echo "$IP success."
        else
                echo "$IP fail"
        fi
done
关键词:Shell

网友留言(0 条)