---
author: Sam White
toc-title: Contents
toc-depth: 5
toc-location: left
date: 2018-07-11 17:01:36+00:00
layout: post
slug: mox-password-less-ssh
title: Mox - Password-less SSH!
categories:
  - 2018
  - Miscellaneous
---

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:





  1. Install `expect`:


    
    <code>sudo apt install expect</code>



  2. Create following script (taken from this [StackExchange solution](https://unix.stackexchange.com/questions/31071/shell-script-for-logging-into-a-ssh-server)):


    
    <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.





  3. Change access to script (set read, write, execute for user only):


    
    <code>chmod u=rwx,go-rwx</code>



  4. Run script from home directory (saved in home directory):


    
    <code>./mox.sh</code>




Boom! No having to track down password, copy, and paste!
