The high performance computing (HPC) cluster (called Mox) at Univ. of Washington (UW) frustratingly requires a password when SSH-ing, even when SSH keys are in use. I have a lengthy, unintelligible password that I use for my UW account, so having to type this in any time I want to initiate a new SSH session on Mox is a painful process.
Today, I finally got fed up with how much time I was wasting (granted, it’s minor in the grand scheme of my day) just logging in to Mox, so I spent some time figuring out how to automate password entry for a new SSH session with Mox.
I tried to handle this using the program sshpass
, but I couldn’t get it to read my password from a file - it would just hang in limbo after executing the command.
In the end, I came across a bash script that does this perfectly. Steps to implement this on Ubuntu 16.04 LTS:
- Install
expect
:
<code>sudo apt install expect</code>
- Create following script (taken from this StackExchange solution):
<code>
#!/usr/bin/expect
spawn ssh mox
expect "Password:"
send "<UW_password>\r"
interact
</code>
NOTES:
* I have an ~/.ssh/config file that allows me to use "mox" as an alias for my full SSH command
* Replace with your own UW password.
- Change access to script (set read, write, execute for user only):
<code>chmod u=rwx,go-rwx</code>
- Run script from home directory (saved in home directory):
<code>./mox.sh</code>
Boom! No having to track down password, copy, and paste!