Last Updated: February 25, 2016
·
5.679K
· gokuu

Using SSH keys other than the default on Mac OS

When trying to use SSH keys other than the default (idrsa and iddsa), to connect to github.com or bitbucket.org, I ran into a problem that caused Mac OSX to always pop up the passphrase dialog, but never accepting the passphrase.

I found that, in order to solve this, I had to do 2 things:

1 - Create a SSH key pair with a passphrase, i.e., not blank
2 - Add the passphrase to the Keychain via ssh-add

Here's what I did:

~ > cd .ssh
.ssh > ssh-keygen -C "e@mail.com"

Generating public/private rsa key pair.
Enter file in which to save the key (/Users/you/.ssh/id_rsa): id_rsa.github
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in id_rsa.github.
Your public key has been saved in id_rsa.github.pub.
The key fingerprint is:
ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff e@mail.com
The key's randomart image is:
+--[ RSA 2048]----+
|.................|
|.................|
|.................|
|.................|
|.................|
|.................|
|.................|
|.................|
|.................|
+-----------------+

To add the passphrase to the Keychain:

.ssh > ssh-add -K id_rsa.github
Enter passphrase for id_rsa.bitbucket: 
Passphrase stored in keychain: id_rsa.github
Identity added: id_rsa.github (id_rsa.github)

Also, make sure you set the correct permissions for the key:

.ssh > chmod 600 id_rsa.github.pub

Note: personal information has been 'obfuscated' :-)