# cat expect.sh
###################
#!/bin/bash
ip=192.168.1.105
pwd="123456"
rm -f ~/.ssh/id_rsa
rm -f ~/.ssh/id_rsa.pub
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
expect -c "
set timeout 10
spawn ssh-copy-id root@${ip}
expect {
*yes/no* {send "yes"\r;exp_continue;}
*assword* {send "${pwd}"\r;}
}
expect -re \](\$|#)
exit
"
############################