Multiple GitHub accounts in the same computer

ech0server

GaMa

Posted on September 18, 2017

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.

👻✌️

💖 💪 🙅 🚩
ech0server
GaMa

Posted on September 18, 2017

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related