Small world. Big idea!
I have two Github accounts: duyhenryer (personal) and duydo (for work). I want to use both accounts on same computer (without typing password everytime, when doing git push or pull).
Generating a new SSH key and adding it to the ssh-agent
π ~/opt/ ❯ mkdir -p ~/.ssh/me
π ~/opt/ ❯ ssh-keygen -t ed25519 -C "[email protected]" -f ~/.ssh/me/id_ed25519
Edit/Create ssh config file (~/.ssh/config)
# For work
Host github.com
HostName github.com
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
# For personal
Host github-me
HostName github.com
IdentityFile ~/.ssh/me/id_ed25519
IdentitiesOnly yes
π ~/opt/ ❯ ssh-add ~/.ssh/id_ed25519
π ~/opt/ ❯ ssh-add ~/.ssh/me/id_ed25519
π ~/opt/ ❯ ssh-add -l # Optional
Guide readers on how to test the SSH connection to ensure it’s working correctly.
π ~/opt/ ❯ ssh -T [email protected]
Hi duydo! You've successfully authenticated, but GitHub does not provide shell access.
π ~/opt/ ❯ ssh -T git@github-me
Hi duyhenryer! You've successfully authenticated, but GitHub does not provide shell access.
π ~/opt/ ❯ git clone git@github-me:duyhenryer/testrepo.git
π ~/opt/ ❯ cd testrepo # develop and modify git config
π ~/opt/ ❯ git config user.name "duyhenryer"
π ~/opt/ ❯ git config user.email "[email protected]"
then use normal flow to push your code
π ~/opt/ ❯ git add .
π ~/opt/ ❯ git commit -m "your comments"
π ~/opt/ ❯ git push
or you can have global git config for work.
π ~/opt/ ❯ git config --global user.name "duydo"
π ~/opt/ ❯ git config --global user.email "[email protected]"