DEV Community

Davide de Paolis
Davide de Paolis

Posted on

3 1

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.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

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.

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay