Use different git SSH keys for different hosts

Last modified date

Comments: 0

Problem

There will be instances where you have repositories in different git hosting services such as GitHub and GitLab.

This means that you will have 2 different SSH keys on your system but you will need to specify which SSH key to use for each host.

But how do you tell git which SSH key to use for each host?

Solution

You need to create a config file in /.ssh file and specify which key to use for each host.

in your /.ssh directory, create a new file called config (/.ssh/config)

In the config file add your hosts and key file names in this format to tell git which key to use for each host:

In the example above, it specifies that when connecting to a GitHub.com host, use the SSH file id_rsa_github.

This will allow you to have multiple SSH keys for multiple git hosts.

Reference

https://superuser.com/a/232406

JakTech

Leave a Reply

Your email address will not be published. Required fields are marked *

Post comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.