Swipe left or right to navigate to next or previous post

Generate multiple SSH Keys for different GitHub accounts

30 Mar 2022 . category: Git . Comments
#GIT #SSH #Server

Ultimate guide to generate multiple SSH Keys for different GitHub accounts

This blog post is about how to generate SSH Keys for different GitHub accounts and use those keys to access different GitHub accounts. The blog is based on the GitHub and Ubuntu Server. However, the concept to create the SSH keys and updating on the source code management system is same.

What is SSH key?

SSH (Secure Shell) is secure cryptographic network protocol to connect with a server. The SSH protocol is mainly used to access the remote servers.

SSH is based on the client server model which perform secure communication between computers with encryption and verification to access, configure the remote server and transmit the files to and from the remote server.

Generate SSH keys for personal GitHub account

For the tutorial purpose, we are considering we have two emails, one for personal use and another for office use. We will use [email protected] as personal email address and [email protected] as business uses or office uses.

Create to .ssh folder

We suggest creating the ssh keys inside the .ssh folder. If folder is not available, create using the following command

    mkdir .ssh
    cd .ssh

Use the following command in terminal to generate the SSH key for personal email

    ssh-keygen -t rsa -C "[email protected]"

This commands will generate something like below

SSH key generation for personal email address

The prompt will ask for the unique name. Enter the unique name that best describe the purpose or type of that email. For the tutorial purpose, we will go with the id_rsa_personal.

It will generate two files inside .ssh folder.

  • id_rsa_personal private file
  • id_rsa_personal.pub: public file which will be used in GitHub

Generate SSH keys for office GitHub account

Use the following command to generate the SSH key for the email

    ssh-keygen -t rsa -C "[email protected]"

It will generate something like below

SSH key generation for office email address

The prompt will ask for the unique name. Enter the unique name that best describe the purpose or type of that email. For the tutorial purpose, we will go with the id_rsa_office.

It will generate two files inside .ssh folder.

  • id_rsa_office: private file
  • id_rsa_office.pub: public file which will be used in GitHub

Setting the public key in the GitHub for personal account

First you need to grab the details on the public file

Grabbing the Details of the id_rsa_personal.pub key

    cat id_rsa_personal.pub

Updating the key in the Github

Steps

  1. Login to your GithHub account with [email protected] email address
  2. Go to setting link. Click on your GitHub profile picture on the right most side. and click settings
  3. On the left most side, you will see th SSH and GPG keys. Click on the link.
  4. On the top towards right side, you will see the New SSH key button. Click that button.
  5. Enter the title that best describes the ssh key.
  6. Enter the grabbed public key in the key section
  7. Finally save by clicking the Add New SSH button.

You will be able to clone, commit the changes to the repo that belongs to [email protected] Github Account

Setting the public key in the GitHub for office account

The steps to grab and set the public key in GitHub account is same as personal email address. Once the public key is updated on the GitHub, one will be able to clone to the repo, push changes to the repo.


Tapan B.K. | Full Stack Software Engineer

Tapan B.K. is Full Stack Software Engineer. In his spare time, Tapan likes to watch movies, visit new places.