Reusing a private SSH key on another Mac

I recently had to access a Git repo which was hosted on Bitbucket on another workstation. Rather than create a new private SSH key, I did the following instead:

  1. Create the ~/.ssh directory (it’s not there by default on a Mac so don’t worry!)
  2. Transfer the SSH key to the other machine (I emailed it which is fine)
  3. Copy the SSH key to the directory and set the permissions
  4. Register the key to the SSH system

At this point, I could git clone the repo and continue development on that workstation. Job done!

You can run this script to do the same, just ensure the private SSH key filename and location is correct (mine was in ~/Downloads/id_rsa) so adjust the first two lines then just copy and paste into a Terminal session:

# the private SSH key we want to install - change these to your private key file location and filename

# create the directory if it doesn't exist
SSH_DIR=~/.ssh && [ ! -d $SSH_DIR ] && mkdir $SSH_DIR

# copy across the private SSH key file

# set restricted permissions

# add the key

Then enter the passphrase for the private key when prompted.

Enjoy! 😉