ssh-copy-id.sh
使用sshpass命令:
#!/bin/bashif [ ! -f ~/.ssh/id_rsa ];thenssh-keygen -f /root/.ssh/id_rsa -N ""elseecho "id_rsa has created ..."fiuser=rootexport SSHPASS=root123for net in {21..250};do{sshpass -e ssh-copy-id -o StrictHostKeyChecking=no $user@192.100.3.$net >/dev/null 2>&1}&done
使用expect命令:
#!/bin/bashif [ ! -f ~/.ssh/id_rsa ];thenssh-keygen -f /root/.ssh/id_rsa -N ""elseecho "id_rsa has created ..."fiuser="root"passwd="root123"for net in {21..250};do{expect <<-EOFset timeout 10spawn ssh-copy-id -i /root/.ssh/id_rsa.pub $user@192.100.3.$netexpect {"yes/no" { send "yes\n";exp_continue }"password" { send "$passwd\n" }}expect "password" { send "$passwd\n" }EOF}&done
