CentOS批量推送密钥

1.方法一

#!/bin/bash
    . /etc/init.d/functions
    
    for ip in {7,31,41}
    do
       sshpass -p123456 ssh-copy-id -i ~/.ssh/id_rsa.pub root@172.16.1.$ip -o StrictHostKeyChecking=no &>/dev/null
       if [ $? -eq 0 ]
       then
          action   "主机 172.16.1.$ip"     /bin/true
		  
       else
          action   "主机 172.16.1.$ip"     /bin/false
		  
       fi
    done

2.方法二

#!/bin/bash
ssh-keygen -t dsa -f /root/.ssh/id_dsa -N ""
for host in 5 6 7 8 9
do
        sshpass -p "1289456" ssh-copy-id -i /root/.ssh/id_dsa.pub "-o StrictHostKeyChecking=no" 172.16.1.${host}
done
posted @ 2019-12-27 10:08  IMSCZ  阅读(223)  评论(0编辑  收藏  举报