If you ever need to write a script that automatically SSHs to another computer, use this script. You’ll find that you cannot automatically SSH for two reasons.
- You can’t pass the password through the ssh command
- You can’t bypass the initial ssh key registration
This script can handle both these problems.
It requires the expect package, which is installed by default on OS X and most Linux distros.
#!/usr/bin/expect
spawn ssh username@hostname – o StrictHostKeyChecking=no
expect “Password:”
send “passwordr”
interact