Home Managing Multiple SSH Keys in Git on Windows
Post
Cancel

Managing Multiple SSH Keys in Git on Windows

  1. Create the first SSH key by running the following command:
    1
    
    ssh-keygen -t rsa -C "someone@example.com" -f "/c/Users/username_for_pc/.ssh/first_username"
    
  2. Next, create the second SSH key by executing the command:
    1
    
    ssh-keygen -t rsa -C "someone2@example.com" -f "/c/Users/username_for_pc/.ssh/second_username"
    
  3. Now, we need to create a config file without any extension. You can either use VS Code or download the config file and modify it. Here’s the content of the config file:
1
2
3
4
5
6
7
8
9
10
11
# GitLab configuration
Host git.chalmers.se
  HostName git.chalmers.se
  User git
  IdentityFile C:\Users\username_for_pc\.ssh\first_username

# GitHub configuration
Host github.com #if both of them are github then you can change the first one to github-second
  HostName github.com
  User git
  IdentityFile C:\Users\username_for_pc\.ssh\second_username
  1. Additionally, we need to edit the .gitconfig file, located at “C:\Users\username_for_pc.gitconfig,” if you have two different Git providers (e.g., GitLab and GitHub). Modify the file as follows:
1
2
3
4
5
6
7
8
9
10
11
[credential "https://git.chalmers.se"]
	provider = generic
[user]
	name = first_username
	email = someone@example.com

[credential "https://github.com"]
	provider = generic
[user]
	name = second_username
	email = someone2@example.com

That’s it! You have successfully configured multiple SSH keys for Git. I hope you find this information helpful.

If you found this post helpful, don’t forget to share it and leave your questions or any additional information you know in the comments below

This post is licensed under CC BY 4.0 by the author.

How to Fix Wrong Committer in Git

Long-term resi­dent status in Sweden

Comments powered by Disqus.