Using two different ssh keys for Github repositories

I have two different users at Github, one is my personal account and the other is the Uetke account. In my personal account I do sometimes play with repositories that nothing have to do with my work and therefore I like keeping things separated. However ssh keys can be used in one account at a time; fortunately the solution is easier than what I would have imaged.

First you setup your new ssh key as you probably did with the first one:

Bash
ssh-keygen -t rsa -C "my_email@example.com"

and remember to store it with a different name than the previous one. For example I will call each key as follows:

Bash
~/.ssh/id_rsa_github1
~/.ssh/id_rsa_github2

And add them

Bash
ssh-add ~/.ssh/id_rsa_github1
ssh-add ~/.ssh/id_rsa_github2
ssh-add -D
ssh-add -l

The last two lines are just for deleting the cached files and then to list the available keys. You can verify that the proper keys were correctly installed by ssh. The last step is to modify the configuration file of ssh to enable the selection of one or the other key:

Bash
cd ~/.ssh/
touch config

Open the newly created config file with whatever editor you like and add the following:

Bash
# Github 1 account
Host github.com-git1
   HostName github.com
   User git
   IdentityFile ~/.ssh/id_rsa_github1

#Github 2 account
Host github.com-git2
   HostName github.com
   User git
   IdentityFile ~/.ssh/id_rsa_github2

The only thing you have to do now is to clone the repository using either github.com-git1 or github.com-git2:

Bash
git clone git@github.com-git1:User1/repo.git

You can also add it as a remote:

Bash
git remote add git@github.com-git2:User2/repo.git

I use this to update repositories into the Uetke profile once they are ready for the public, but in the meantime I use my personal repository for myself or extremely curious people.

Header photo by Cristina Gottardi on Unsplash

Support us
If you like the content of this website, consider buying a copy of the book Python For The Lab

Other interesting articles for you

How to Encrypt an External Drive on Linux

External drives are a great complement to laptops with a limited amount of memory. The data you generate in the lab may not fit on the SSD drive of your ultrabook, or you want to keep access to older information. Not only scientific data takes a lot of space, also …

read more

Uetke's website is on Github

At Uetke we seek to build simple, clear, modular and extensible codes that can be easily maintained and repurposed by developers other than their creators. Therefore we decided to make all the under-the-hood code freely available for others to read, learn, and improve. The code is hosted on Github in …

read more

New Courses of Git for Scientists

We are launching the course Git for Scientists aimed at researchers from different backgrounds and career stages. In the course, you will learn how to work with git, one of the best version control system of all times, and its different web implementations such as BitBucket, GitHub, and GitLab.

Git …

read more

The Importance of Doing a Backup

The ransomware attacks that occurred some months ago triggered a wave of people concerned about backups, finally! Ransomware attacks encrypted entire hard drives and the only way of recovering the data was by paying money to the hackers. This kind of attack is simply bypassed by a good back up …

read more

Agile Development for Science

Managing research projects and teams can benefit from the methodologies and processes developed in other fields of management. In recent decades, software development became a major industry that needed to establish its own set of rules and procedures. People working in the software industry and young scientists such as Ph …

read more
Subscribe

Get all the information directly to your inbox

Get relevant information, unsubscribe at any time.

© Copyright 2018 Uetke | Contact Us | RSS feed | Privacy Policy | Cookies