DEV Community

Davide de Paolis
Davide de Paolis

Posted on

Store your git ssh in keychain (and make it persist across logins)

Expecially during these times of remote work, I happened to be switching among different devices many times. I found very annoying that every time I needed to run some git push or pull I was asked for my git credentials.

I have an SSH key for that!

To use that key you need to add it to your keychain :

ssh-add -K ~/.ssh/[your-private-key]
Enter fullscreen mode Exit fullscreen mode

This works pretty well, until you restart... If you are on Catalina you have to persistently store the key with a specific configuration:

touch .ssh/config
vi .ssh/config
--> i  ( to start typing in the file )
Host *
  UseKeychain yes
  AddKeysToAgent yes
  IdentityFile ~/.ssh/id_rsa
--> ESC (to exit from editing)
:wq  ( to save and close)
Enter fullscreen mode Exit fullscreen mode

Credits go to this answer on Apple.StackExchange but this issue kept occurring to me and I found myself having to constantly google for it, so I decided to saving it here for future reference.

Top comments (3)

Collapse
 
prometheas profile image
John Lianoglou

Propose updating the commands:

touch .ssh/config
vi .ssh/config
Enter fullscreen mode Exit fullscreen mode

To explicitly resolve the file as follows:

touch ~/.ssh/config
vi ~/.ssh/config
Enter fullscreen mode Exit fullscreen mode
Collapse
 
iob profile image
Yiannis

for non-osx system(i use fedora) the same works without the UseKeychain

Collapse
 
crimsonmed profile image
Médéric Burlet

Even pre-catalina the restart is not handled.