DEV Community


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:

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/
Enter fullscreen mode Exit fullscreen mode

Add the key to GitHub


Back in the container configure git:

git config --global "[email]"
git config --global "[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)

engineercoding profile image
Wesley Ameling

While it seems like a solution, I think it is not that elegant. You could setup a got user per directory:

And you can manage the SSH keys with a SSH config file. I couldn't find the resource I used for that, but if you are interested in that I can write a small post about it. Should also help other people at that same time :)

ech0server profile image

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 :)

ewoks profile image

example in "Multiple SSH Keys" section

An Animated Guide to Node.js Event Loop

Node.js doesn’t stop from running other operations because of Libuv, a C++ library responsible for the event loop and asynchronously handling tasks such as network requests, DNS resolution, file system operations, data encryption, etc.

What happens under the hood when Node.js works on tasks such as database queries? We will explore it by following this piece of code step by step.