SSH Keys

Create new SSH keys

Follow the GitHub guide:

Migrate SSH keys to a new computer

This is a little tricky, but easier than changing SSH key everywhere you authenticate with SSH.

Copy these files from your old to new computer:

~/.ssh/config
~/.ssh/id_rsa
~/.ssh/id_rsa.pub

Note: I skipped copying the ~/.ssh/known_hosts file. Stuff builds up. We’ll start fresh later.

Add your SSH key to the ssh-agent (reference):

# Start the SSH agent
eval "$(ssh-agent -s)"

# Add the key
ssh-add -K ~/.ssh/id_rsa

You’ll be prompted to enter the passphrase (mine is saved in 1Password).

The ~/.ssh/known_hosts file needs to be seeded with connections next.

Test the GitHub connection, and verify the response (reference):

ssh -T git@github.com

Test the Bitbucket connection, and verify the response (reference):

ssh -T git@bitbucket.org

Try fetching from your repos, and it should work.

Issues

macOS 10.12.2

Apple stopped saving SSH passphrases in its keychain in macOS 10.12.2, which is a pain in the ass because Git prompts for your passphrase after every command.

Long term fix

Create/edit this file to fix it: ~/.ssh/config

Host *
  UseKeychain yes
  AddKeysToAgent yes
  IdentityFile ~/.ssh/id_rsa

Host entries are matched first ➔ last, so this may need to be repeated in each additional host entry.

Short term fix

Needs to be repeated after every restart.

ssh-add -K ~/.ssh/id_rsa

You could add this to your bash profile so every terminal session starts, but people say it’s slow.