Throughout time in developments we faced multiple repositories with different git account/credentials. Managing multiple Git accounts and ensuring commit authenticity can be challenging.
This guide simplifies the process by combining multi-account SSH key setup with GPG signing for secure authentication and trusted commits across your Linux, Windows, and macOS workstation.
Why It Matters
SSH Keys: Manage multiple accounts securely with password-free access. Essential for handling separate work, personal, or client repositories without confusion.
GPG Signing: Cryptographically sign commits to prove their authenticity and protect them from tampering—critical for secure, professional or enterprise collaborations.
- This workflow is also apply to other git service provider such as gitlab or bitbucket.
Steps
Typical steps to enabling multi-account Git SSH & GPG commit signing, you can check this big picture on how we enabling it.
- Create SSH Key in workstation for each account with distinct name.
- Save your SSH Public Key to github.
- Create gpg key and save to github.
- Clone using git SSH for push access to the repo.
- Config the local git repo folder to configure username, email account and signing commit using your gpg key.
- For complete details you can follow the rest of this article.
1. Setting Up Multi-Account Git with SSH
Step 1: Generate SSH Keys
For each Git account, generate a separate SSH key.
Linux/macOS:
ssh-keygen -t rsa -b 4096 -C "[email protected]" -f ~/.ssh/id_rsa_personal
ssh-keygen -t rsa -b 4096 -C "[email protected]" -f ~/.ssh/id_rsa_client
Windows (Git Bash):
ssh-keygen -t rsa -b 4096 -C "[email protected]" -f ~/ssh/id_rsa_personal
ssh-keygen -t rsa -b 4096 -C "[email protected]" -f ~/ssh/id_rsa_client
Important notes
- During SSH Key Generation, user is your github username and email is your email registered for your github account.
- " and run:
CODEgpg --full-generate-key
Choose
RSA and RSA (4096 bits)and set an expiry date.
Step 2: Export the Public Key
Find the GPG key ID:
CODEgpg --list-secret-keys --keyid-format LONG
Export and copy the key:
CODEgpg --armor --export <GPG_KEY_ID>
Step 3: Add GPG Key to GitHub
- Go to GitHub > Settings > SSH and GPG Keys > New GPG Key.
- Paste the public key.
4. Configuring Repository-Specific Settings
For each repository, configure local Git settings to specify the username, email, and GPG key.
CODEcd /path/to/repo
git config user.name "Your Name"
git config user.email "[email protected]"
git config user.signingkey <GPG_KEY_ID>
git config commit.gpgsign true
Verify settings with:
CODEgit config --get user.name
git config --get user.email
git config --get user.signingkey
This ensures commits in the repository use the correct identity and are signed.
5. Using and Verifying Signed Commits
Create a Signed Commit
CODEgit commit -S -m "Your commit message"
Verify Signed Commits
CODEgit log --show-signature
Git will display the signature status, confirming commit authenticity.
Conclusion
Combining multi-account SSH key management with GPG signing ensures secure, streamlined workflows for professional developers. Whether you're managing personal, work, or client repositories, this setup keeps your Git environment organized, authenticated, and trustworthy.
↗ Original-Artikel auf dev.to lesenVollständiger Original-BerichtAusführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to. - Go to GitHub > Settings > SSH and GPG Keys > New GPG Key.
SOCIAL SHARE CARD GENERATOR