实现免密登录
vim ./passwd passwd="xxxxxxxx"
#!/bin/bash source ./passwd function secret_free_login(){ ls /root/.ssh/id_rsa.pub &> /dev/null if [ $? -eq 0 ];then for i in ${node[@]} do sshpass -p "$passwd" ssh root@$i "mkdir /root/.ssh &>/dev/null" sshpass -p "$passwd" scp /root/.ssh/id_rsa.pub root@$i:/root/.ssh/authorized_keys done else ssh-keygen -N '' -f /root/.ssh/id_rsa for p in ${node[@]} do sshpass -p "$passwd" ssh root@$p "mkdir /root/.ssh &>/dev/null" sshpass -p "$passwd" scp /root/.ssh/id_rsa.pub root@$p:/root/.ssh/authorized_keys done fi echo "secret_free_login ok" }
标签:脚本,功能,shell,passwd,rsa,ssh,sshpass,root,id From: https://www.cnblogs.com/gsda/p/17165412.html