第二个:ssh秘钥分发脚本

#管理机创建公钥(dsa)
ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa >/dev/null 2>&1

#服务器密码统一,可以这样玩
password=123456

#分发密钥
for i in "192.168.10.10" "192.168.10.11" "192.168.10.12" 
    do
        sshpass -p $password ssh -o StrictHostKeyChecking=no $i "mkdir -m 700 -p ~/.ssh/"
        sshpass -p $password scp -o StrictHostKeyChecking=no ~/.ssh/id_dsa.pub root@$i:~/.ssh/authorized_keys
        sshpass -p $password ssh -o StrictHostKeyChecking=no $i "chmod 600 ~/.ssh/authorized_keys"
    done
转载老司机:http://blog.51cto.com/linux1991/2125583

你可能感兴趣的:(Linux基础)