sshpass批量分发ssh秘钥

首先安装sshpass:

yum -y install sshpass

单条命令:  

sshpass -p“password” ssh-copy-id -i /root/.ssh/id_rsa.pub "-o StrictHostKeyChecking=no -p xxxx root@X.Y.Z.A"

批量:

1 #!/bin/bash
2
3 for host in $(cat pass)
4 do
5 ip=$(echo ${host} | cut -f1 -d ":")
6 port=$(echo ${host} | cut -f2 -d ":")
7 password=$(echo ${host} | cut -f3 -d ":")
8 sshpass -p ${password} ssh-copy-id -i /root/.ssh/id_rsa.pub "-p ${port} -o StrictHost KeyChecking=no root@${ip}"
9 done

pass文件格式

1 IP:port:password

 

posted @ 2018-11-15 17:21  千米屠苏  阅读(712)  评论(0编辑  收藏  举报