shell脚本实现ssh全自动创建秘钥并分发

#!/bin/bash
#haha,xiedediyigeshell
# lijiapeng  qq: 1002261270    2014/1/14
ssh-keygen -t rsa
for i  in {2..5} ;do
    /usr/local/bin/sshpass  -p 123123 ssh [email protected].$i "mkdir .ssh"
    /usr/local/bin/sshpass  -p 123123 scp /root/.ssh/id_rsa.pub 192.168.2.$i:/root/.ssh/id_rsa.pub
    /usr/local/bin/sshpass  -p 123123 scp /root/.ssh/authorized_keys  192.168.2.$i:/root/.ssh/authorized_keys
    sshpass -p 123123 ssh [email protected].$i "cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys"
done



ps:sshpass需要自行安装

本文出自 “lijp” 博客,转载请与作者联系!

你可能感兴趣的:(shell,ssh自动化,ssh秘钥)