I have a single computer and different GitHub accounts. I cannot use the same SSH key twice, which means I have to create a new SSH key for each GitHub account.
ssh-keygen -t ed25519 -C "[email protected]"
Add the public SSH key to your GitHub account: Settings
-> SSH and GPG keys
-> New SSH key
Configure your SSH config (~/.ssh/config
).
Host gh_work
HostName github.com
IdentityFile ~/.ssh/id_ed25519_work
Host gh_personal
HostName github.com
IdentityFile ~/.ssh/id_ed25519_personal
git clone git@gh_work:foo/bar.git
If you have an existing repository, change the remote url.
git remote set-url origin git@gh_work:foo/bar.git