Quick Temporary ssh key login

If you often code from different machines, you may want a quick way to activate your github ssh credentials on a machine for a limited amount of time. To do this, you can use a passphrase-protected SSH key stored on an encrypted USB drive. The rest of this message contains directions walking you through all of the setup for that, which, on a good day, takes about 10-15 minutes.

In case you haven't yet set up an encrypted USB drive yet, here are directions on how to encrypt an entire USB drive.

From there, you can follow GitHub's directions for adding a new SSH key to your account, making sure to save the key on your now-encrypted drive (not the default location in your home directory). Please use a password different from the USB drive's password and different from your GitHub account password.

Then, to make it super-easy to just plug in your USB key and activate your SSH key for a limited time, you can follow this example:

$ ls /Volumes/SarasUSB/
total 8
-rwxr-xr-x  1 sara   176B  4 Feb 17:39 add_key*
-rw-------  1 sara   1.7K  4 Feb 11:20 id_rsa

$ cat /Volumes/SarasUSB/add_key
#!/usr/bin/env bash

HOURS=$1

if [ -z $HOURS ]; then
  echo "Usage: $0 <num hours>"
  exit 1
fi

ssh-add -t ${HOURS}H $(dirname $0)/id_rsa
diskutil umount force $(dirname $0)

$ /Volumes/SarasUSB/add_key
Usage: /Volumes/SarasUSB/add_key <num hours>

$ /Volumes/SarasUSB/add_key 1
Enter passphrase for /Volumes/SarasUSB/id_rsa:
Identity added: /Volumes/SarasUSB/id_rsa (/Volumes/SarasUSB/id_rsa)
Lifetime set to 3600 seconds
Volume SarasUSB on disk6 force-unmounted

Just plug your key in, run /Volumes/SarasUSB/add_key 1, and put your key back in your pocket. You'll be able to git push and pull for 1 hour.

Whether you use a script like above or just manually ssh-add -t 8H /Volumes/your_drive/id_your_key, make sure that you always add the SSH key with a time limit so that you aren't accidentally logged in to a station permanently.