#!/usr/bin/bash
host=$1
username=$2
password=$3
if [ -f "/root/.ssh/id_rsa.pub" ];then
echo "key exist!!"
else
ssh-keygen -t rsa -b 1024 -f /root/.ssh/id_rsa -P '' -q
echo "create key-pair!!"
fi
/usr/bin/expect <<-EOF
spawn ssh-copy-id -f -i /root/.ssh/id_rsa.pub $username@$host;
expect {
"(yes/no)?" {
send "yes\r";
expect "*password:";
send "$password\r";
}
"*password:" {
send "$password\r";
}
}
expect eof;
EOF