There might be a chance that you need to create and use a separate github(or bitbucket) account other than your personal one in your workplace. And Github(Bitbucket or Gitlab will do the same I believe) doesn’t allow to share a ssh key between different accounts for authentication.

That’s the case we are going to figure out below.

First of all, create a new ssh key pair on your machine.

1
2
3
ssh-keygen -t ed25519 -C "[email protected]"
# Note: If you are using a legacy system that doesn't support the Ed25519 algorithm, use:
ssh-keygen -t rsa -b 4096 -C "[email protected]"

Next, edit/create the ssh config file.

1
vim ~/.ssh/config
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Default github account: crazyoptimist
Host github.com
   HostName github.com
   IdentityFile ~/.ssh/id_rsa
   IdentitiesOnly yes

# Workplace github account: extremeoptimist
Host github-workplace   # <-- This is the hostname that you will actually add by `git remote add`
   HostName github.com
   IdentityFile ~/.ssh/id_ed25519
   IdentitiesOnly yes

Test the ssh authentication.

1
2
ssh -T [email protected]
ssh -T git@github-workplace

Now you should be able to clone repos in your workplace org.

1
git clone git@github-workplace:your-org/some-cool-project.git

You got an idea to do this in a better way? Then you got it!

Happy coding!