I recently got a github account from my employer. So now i do have two github account, my private one and my work account.
Sometimes i do work on my work machine but want to update some source that is under my private github account. This does not work, at least not out of the box, since on my work machine also my github work account is configured. Github, off course, does not allow my work account to update a repository from my private account.
I solved the problem by:
- adding a ssh key which is allowed to alter to my private account, onto my work machine.
- adding a alias into ssh config
- change the git URL in my private repositories (on my work machine) to match the alias (from ssh config)
Here are the details:
adding a new (private) ssh key
The SSH Key id_ed25519_analyzr3
is one that is permitted to access my private account.
in my ~/.bashrc
i make sure it gets loaded into the ssh agent when i login or start a bash shell.
This i do with the following line. You can also do this manually each time you need to.
ssh-add ~/.ssh/id_ed25519_analyzr3
adding an alias into ~/.ssh/config
The second step is to add a host alias into my ssh config file, usually located at ~/.ssh/config
.
Host scusi-github.com
HostName github.com
IdentityFile ~/.ssh/id_ed25519_analyzr3
User git
change origin URL in repository git config
The last step is to change the local git config file of my (private) repository, to match my alias just added to my ssh config.
So i change the origin url from git@github.com:scusi/SomeRepo.git
into git@scusi-github.com:scusi/SomeRepo.git
The relevant part looks like this, after editing
[remote "origin"]
url = git@scusi-github.com:scusi/SomeRepo.git
That’s it. Now i can work as normal on my work machine and update work related repositories as before. When i work on a repository from my private account i just clone it, change the URL to match the ssh config alias and that’s it. A git push
works as normal, but under the hood authenticates useing a different ssh key, which is has the neccessary permissions.