All Topics
All Topics
Technology
Technology
Design
Design
Programming
Programming
Science
Science
News
News
Gaming
Gaming
Entertainment
Entertainment
Business
Business
Finance
Finance
Sports
Sports
Health
Health
Food
Food
Travel
Travel
Art
Art
Music
Music
Books
Books
Education
Education
Politics
Politics
Personal
Personal
No algorithm. No AI slop. No ads. Just RSS. Pro-human. Indie writers. Real journalism. Open web. Chronological. Hand toasted.

Managing SSH Keys in .git Directory for Repository Portability and Account Isolation

By

dansjots

5mo ago· 3 min readen

Summary

The article describes a technical solution for managing SSH keys in Git repositories to prevent accidental pushes from the wrong account. The author explains how they store SSH keys directly in the .git directory of each repository, making repositories portable across different machines via USB drives. This approach uses deploy keys exclusively and avoids credential confusion by keeping authentication credentials repository-specific rather than machine-wide.

Key quotes

· 3 pulled
My repository remotes are set up to use deploy keys exclusively, as I don't want to inadvertently push changes from the wrong account due to forgetting to change the local machine user's credentials.
I used to do so by keeping several subdirectories inside my .ssh directory for per-account keys and manually pasting them outside whenever I want to push a specific repo, but it's cumbersome and still quite error-prone.
Eventually I came across this SuperUser answer and adapted it with my slight twist leveraging the fact that the .git directory's contents are well-behaved.
Snippet from the RSS feed
My repository remotes are set up to use deploy keys exclusively, as I don’t want to inadvertently push changes from the wrong account due to forgetting to change the local machine user’s credentials.

You might also wanna read