Skip to content

Configuring Multiple SSH in Ubuntu

Shamik edited this page Dec 11, 2023 · 2 revisions

Configuring Multiple SSH in Ubuntu 20.04 for Github

If you haven't generated SSH for Github and would like to know more about the same, please refer to this guide.

If you have multiple Github accounts, i.e. one for work and the other personal, then this guide is perfect for you. The need to have multiple SSH keys arise, when you would want to use work repos for certain projects and personal repos for others.

Generating a ssh config file and updating the ssh info

  • Generate SSH keys on Ubuntu for you work and personal Github accounts
  • Create a ssh config file under the ~/.ssh directory
    • vim ~/.ssh/config and the input the below lines
<!-- For personal profile -->
Host personal-github
    HostName github.com
    User git
    IdentityFile ~/.ssh/personal_id_ed25519

<!-- For work profile -->
Host work-github
    HostName github.com
    User git
    IdentityFile ~/.ssh/work_id_ed25519

An example of the ssh_config file can be found here. Rename this file to config and replace the contents.

There are two parameters, which are configurable i.e. Host & IdentityFile. The first can be any string you choose, in my case it is personal-github & work-github and the second needs to be path to the Identityfile for the personal and work ssh ids.

Checking ssh connections for personal and work

For personal

ssh -T personal-github

You will notice a similar outputHi Shamik-07! You've successfully authenticated, but GitHub does not provide shell access.

For work

ssh -T work-github

You will notice a similar outputHi shamik-biswas-rft! You've successfully authenticated, but GitHub does not provide shell access.

Cloning with work ssh

Normally if one would like to clone a repo, e.g. https://github.com/Shamik-07/CodeSnippets, through ssh:

However, since this is a work repo and not accessible through personal Github account, it would be

  • git clone work-github:Shamik-07/CodeSnippets.git

Difference between both commands

git clone [email protected]:Shamik-07/CodeSnippets.git
git clone work-github:Shamik-07/CodeSnippets.git
The hostname [email protected] must be replaced by either of the hosts defined in the config file.