ssh-copy-id.sh
使用sshpass命令:
#!/bin/bash
if [ ! -f ~/.ssh/id_rsa ];then
ssh-keygen -f /root/.ssh/id_rsa -N ""
else
echo "id_rsa has created ..."
fi
user=root
export SSHPASS=root123
for 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/bash
if [ ! -f ~/.ssh/id_rsa ];then
ssh-keygen -f /root/.ssh/id_rsa -N ""
else
echo "id_rsa has created ..."
fi
user="root"
passwd="root123"
for net in {21..250};do
{
expect <<-EOF
set timeout 10
spawn ssh-copy-id -i /root/.ssh/id_rsa.pub $user@192.100.3.$net
expect {
"yes/no" { send "yes\n";exp_continue }
"password" { send "$passwd\n" }
}
expect "password" { send "$passwd\n" }
EOF
}&
done