DEV Community

GaMa
GaMa

Posted on

Multiple GitHub accounts in the same computer

Due to work I faced the need of using two or more GitHub accounts, sometimes I need to use the accounts in the same machine. I've been trying to use the following solution:

https://code.tutsplus.com/tutorials/quick-tip-how-to-work-with-github-and-multiple-accounts--net-22574

However I couldn't make it to work, by the time I was experimenting with Docker and I got the idea of using a container to just push my changes. So far I haven't identify any security related problems, obviously never expose the container to internet just start it push your changes and stop it, or script it to launch it add the new ssh keys to github push then destroy the container.

The solution is quite simple, start a new container from the image I created in an earlier post: Creating the Docker image

First of all pull the image:

docker pull drverboten/multigitaccount
Enter fullscreen mode Exit fullscreen mode

Then create a new container from the image, but add the path of the source code or any other resource you want to add to your repo as a volume with the -v option:

docker run -it --name gitpub -v /home/[user]/[path to workspace]:/workspace drverboten/multigitaccount /bin/sh
Enter fullscreen mode Exit fullscreen mode

After the container is running, create a new ssh key with the following command:

ssh-keygen -t rsa -b 4096 -C "[email]"
Enter fullscreen mode Exit fullscreen mode

Copy your key to the clipboard you can just cat and copy the text:

cat ~/.ssh/id_rsa.pub
Enter fullscreen mode Exit fullscreen mode

Add the key to GitHub

GitHub

Back in the container configure git:

git config --global user.email "[email]"
git config --global user.name "[username]"
Enter fullscreen mode Exit fullscreen mode

And you are all set, just push to GitHub as you normally do, it will post as the configured user.

👻✌️

Top comments (3)

Collapse
 
ech0server profile image
GaMa

Thank you, if you can write it, it would be great. I came with this "solution" because I did not wanted to spend time looking why I couldn't make it work in any other way I could google, so I went with what I knew :)

Collapse
 
ewoks profile image
Beeblebrox

example in "Multiple SSH Keys" section dev.to/aravindballa/advanced-git-t...