Setting Up Multiple Git Profiles with SSH and Commit Signing

Learner going on journey to be full stack (MERN)developer
Many developers work with multiple GitHub accounts—one for personal projects and another for work. Managing multiple accounts with SSH authentication and commit signing can be tricky, but in this guide, I'll walk you through setting up both seamlessly.
for windows use either Git Bash or PowerShell
Generate Separate SSH Keys
We need two separate SSH keys: one for your personal GitHub and another for your work GitHub.
Run the following commands to generate them:
ssh-keygen -t ed25519 -C "yourpersonal@email.com" -f ~/.ssh/id_ed25519_personal ssh-keygen -t ed25519 -C "yourwork@email.com" -f ~/.ssh/id_ed25519_workssh-keygen -t ed25519 -C ‘yourpersonal@email.com’this part will create ssh key-f ~/.ssh/id_ed25519_personal-f stands for file and it will make sure our file is saved with name we provide.This will create two key pairs:
Personal:
~/.ssh/id_ed25519_personaland~/.ssh/id_ed25519_personal.pubWork:
~/.ssh/id_ed25519_workand~/.ssh/id_ed25519_work.pubConfigure SSH for Multiple Accounts
we’ll configure SSH to use the correct key for each GitHub account. Edit or create your SSH config file:
For Mac:
nano ~/.ssh/configFor windows:
notepad $env:USERPROFILE\.ssh\configAdd the following configuration:
# Personal GitHub Host github-personal HostName github.com User git IdentityFile ~/.ssh/id_ed25519_personal IdentitiesOnly yes # Work GitHub Host github-work HostName github.com User git IdentityFile ~/.ssh/id_ed25519_work IdentitiesOnly yesConvert the file to Unix format and set permissions:
For Mac:
tr -d '\r' < ~/.ssh/config > ~/.ssh/config_fixed && mv ~/.ssh/config_fixed ~/.ssh/config chmod 600 ~/.ssh/configFor Windows:
(Get-Content $env:USERPROFILE\.ssh\config) -replace "`r", "" | Set-Content $env:USERPROFILE\.ssh\config icacls $env:USERPROFILE\.ssh\config /inheritance:r /grant:r "$($env:USERNAME):(R,W)"Test the SSH Connection
Run these commands to verify:
ssh -T git@github-personal ssh -T git@github-workIf configured correctly, you should see:
Hi yourusername! You've successfully authenticated... Hi yourworkusername! You've successfully authenticated..Add SSH Keys to GitHub
Copy each public key and add it to the respective GitHub account under Settings → SSH and GPG Keys.:
cat ~/.ssh/id_ed25519_personal.pub cat ~/.ssh/id_ed25519_work.pubConfigure Git to Use Different Profiles
Set up global config for your personal account:
git config --global user.name "Your Personal Name" git config --global user.email "yourpersonal@email.com"For work repositories, override this with local config:
cd ~/work-repo git config --local user.name "Your Work Name" git config --local user.email "yourwork@email.com"/work-repohere can be either you git repo or root directory under which you will clone all work reposSet Up Commit Signing for Both Accounts
GitHub allows you to sign commits using SSH keys. First, configure Git to use SSH signing:
git config --global gpg.format sshPersonal Signing Key
git config --global user.signingkey ~/.ssh/id_ed25519_personal.pub git config --global commit.gpgsign trueWork Signing Key (Local Override)
Inside your work repository:
git config --local user.signingkey ~/.ssh/id_ed25519_work.pub git config --local commit.gpgsign trueAdd SSH Signing Key to GitHub
Go to GitHub → Settings → SSH and GPG Keys → New SSH Key and select Signing Key. Paste your SSH public key (
.pub).Configure Allowed Signers for Verification
Create a file to list trusted signing keys:
For Mac:
touch ~/.ssh/allowed_signersFor Windows:
New-Item -ItemType File -Path $env:USERPROFILE\.ssh\allowed_signersEdit it (Mac):
nano ~/.ssh/allowed_signersEdit it (windows):
notepad $env:USERPROFILE\.ssh\allowed_signersAdd the following lines:
<yourpersonalusername> ssh-ed25519 <public key for personal account> <yourworkusername> ssh-ed25519 <public key for work account>Convert the file to Unix format and set permissions:
For Mac:
tr -d '\r' < ~/.ssh/allowed_signers > ~/.ssh/allowed_signers_fixed && mv ~/.ssh/allowed_signers_fixed ~/.ssh/allowed_signers chmod 600 ~/.ssh/allowed_signersFor Windows:
(Get-Content $env:USERPROFILE\.ssh\allowed_signers) -replace "`r", "" | Set-Content $env:USERPROFILE\.ssh\allowed_signers icacls $env:USERPROFILE\.ssh\allowed_signers /inheritance:r /grant:r "$($env:USERNAME):(R,W)"Configure Git to use it
For Mac:
git config --global gpg.ssh.allowedSignersFile ~/.ssh/allowed_signersFor windows:
git config --global gpg.ssh.allowedSignersFile $env:USERPROFILE\.ssh\allowed_signersSetting work repositories:
For Mac:
git config --local gpg.ssh.allowedSignersFile ~/.ssh/allowed_signersFor Windows:
git config --local gpg.ssh.allowedSignersFile $env:USERPROFILE\.ssh\allowed_signersVerify Signed Commits
Make a test commit in one of your repos:
git commit -S -m "Test signed commit"verify if it works:
git log --show-signatureIf everything is correct, you should see:
Good signature from SSH key ID SHA256:xxxxxxxxAnd GitHub will show commits as "Verified". ✅
