SSH Config for Multiple SSH Authentication

TL;DR

Having multiple SSH keys is useful when you want to separate the purpose of each key, for example you want to have a different SSH keys for GitLab and GitHub for whatever reason. This can be achieved via the config file.

Crea…


This content originally appeared on DEV Community and was authored by Mikhael Esa

TL;DR

Having multiple SSH keys is useful when you want to separate the purpose of each key, for example you want to have a different SSH keys for GitLab and GitHub for whatever reason. This can be achieved via the config file.

Creating Config File

To be able to have multiple ssh for different purpose, we need to create a config file inside the .ssh directory.

$ cd ~/.ssh
$ touch config
$ vim config

The commands above will directs us to the .ssh directory and creates the config file and then uses vim to edit the content. You can use other editor like nano, it's up to you.

Now let's edit the config file to look like this.

Host gitlab.com
    HostName gitlab.com
    User git
    IdentityFile ~\.ssh\my_gitlab_ssh
    IdentitiesOnly yes

Host github.com
    HostName github.com
    User git
    IdentityFile ~\.ssh\my_github_ssh
    IdentitiesOnly yes

Now there you have it, a ssh config file for multiple SSH keys. You are not limited to only GitHub and GitLab, you can also use it for server authentication and many more.

~ Dadah 👋


This content originally appeared on DEV Community and was authored by Mikhael Esa


Print Share Comment Cite Upload Translate Updates
APA

Mikhael Esa | Sciencx (2024-07-05T12:33:49+00:00) SSH Config for Multiple SSH Authentication. Retrieved from https://www.scien.cx/2024/07/05/ssh-config-for-multiple-ssh-authentication/

MLA
" » SSH Config for Multiple SSH Authentication." Mikhael Esa | Sciencx - Friday July 5, 2024, https://www.scien.cx/2024/07/05/ssh-config-for-multiple-ssh-authentication/
HARVARD
Mikhael Esa | Sciencx Friday July 5, 2024 » SSH Config for Multiple SSH Authentication., viewed ,<https://www.scien.cx/2024/07/05/ssh-config-for-multiple-ssh-authentication/>
VANCOUVER
Mikhael Esa | Sciencx - » SSH Config for Multiple SSH Authentication. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/07/05/ssh-config-for-multiple-ssh-authentication/
CHICAGO
" » SSH Config for Multiple SSH Authentication." Mikhael Esa | Sciencx - Accessed . https://www.scien.cx/2024/07/05/ssh-config-for-multiple-ssh-authentication/
IEEE
" » SSH Config for Multiple SSH Authentication." Mikhael Esa | Sciencx [Online]. Available: https://www.scien.cx/2024/07/05/ssh-config-for-multiple-ssh-authentication/. [Accessed: ]
rf:citation
» SSH Config for Multiple SSH Authentication | Mikhael Esa | Sciencx | https://www.scien.cx/2024/07/05/ssh-config-for-multiple-ssh-authentication/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.