#管理機建立公鑰 ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa >/dev/null 2>&1 #服務器密碼統一,能夠這樣玩 password=123456 #分發密鑰 for i in $@ 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