-
Notifications
You must be signed in to change notification settings - Fork 0
Configuring Multiple SSH in Ubuntu
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.
- 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.
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.
Normally if one would like to clone a repo, e.g. https://github.com/Shamik-07/CodeSnippets, through ssh:
git clone [email protected]:Shamik-07/CodeSnippets.git
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
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.