简体   繁体   中英

Enable Multiple SSH Key for GitHub on Windows 10

I have 2 GitHub account and I can't use the same public key for both accounts. I have already generated 2 ssh key

  • C:\Users\{User_Name}\.ssh\id_rsa
  • C:\Users\{User_Name}\.ssh\id_rsa_another

My question is, how I can use multiple ssh keys for Windows? On Linux, I just have to add by using ssh-add command, but on Windows, this command does not exist.

What have I done to make the other ssh key work, I have to change the id_rsa to id_rsa_temp and id_rsa_another to id_rsa . I know this is stupid.

First, ssh-add exists on Windows, as part of Git For Windows:

C:\Users\vonc>where ssh-add
C:\Program Files\Git\usr\bin\ssh-add.exe

It is needed for caching the passphrase protecting a private key (which is not always needed, since you can create a private key without passphrase)

Using different account, as commented, uses a %USERPROFILE%.ssh\config file, with in it:

Host gh1
  Hostname github.com
  User git
  IdentityFile ~/.ssh/id_rsa
Host gh2
  Hostname github.com
  User git
  IdentityFile ~/.ssh/id_rsa_another

You can test them with:

ssh -Tv gh1
ssh -Tv gh2

You should see a different "Welcome" message per key.

And the URL to use for cloning your repo would be:

gh1:user1/repo1
gh2:user2/repo2

Finally, I found the solution

I have to use Git Bash because I can't use a regular Windows terminal when running this command

$ eval $(ssh-agent -s)

And then I can add the SSH key by running this command

$ ssh-add C:/Users/{User_Name}/.ssh/id_rsa_another

We must use the forward-slash for the path

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM