#!/bin/bash
function setup_pwless_login
{
cat > vm-pwless-login-setup.exp <<-EOF
#!/usr/bin/expect
set timeout 180
set send_slow {1 .01}
log_user 1
eval spawn ssh-copy-id -f -p2222 "root\@localhost"
expect {
timeout { send_user "timeout\n"; exit }
"*assword: " { send -s "root\r\r\r" }
}
wait
EOF
echo "Please be patient while setting up automatic login to the VM."
echo "This might take a bit of time..."
expect -f ./vm-pwless-login-setup.exp
echo "Done."
rm ./vm-pwless-login-setup.exp
}
setup_pwless_login