1

Let's first describe the problem that I've faced:

  • I've two PC, one of them is the Windows machine and the other one is the Linux machine.

  • I want to generate two SSH public key on both of these machines. One is for my GitHub account and the other one is for my GitLab account.

  • I have used the following commands to generate the public SSH key which is perfectly work in my Linux machine but not in the Windows machine.

Commands:

Step 1: Generate SSH Key

ssh-keygen

Step 2: Write the directory and file name where I want to save the SSH key.

[ For my case, I've inserted the windows path in below ]

/c/Users/PC_USER_NAME/.ssh/id_rsa_hub

Step 3: Get the public key from the file

cat ~/.ssh/id_rsa_hub.pub

These steps perfectly work on my Linux machine but on Windows, I saw the authentication error. How can I configure the SSH public key's?

Bappa Lenard
  • 103
  • 1
  • 8

2 Answers2

1

For the windows machine, you have to do one more configuration. Just follow the steps in below (if you're using the Git Bash):

  1. Go to the .ssh directory /c/Users/PC_USER_NAME/.ssh/, click right mouse button and choose "Git Bash Here"
  2. Create a file named "config" with the following command:
touch config
  1. Now open the config file with the command:
nano config
  1. Now write the following lines inside the config file

Let's assume you've created two files named id_rsa_hub for Github and id_rsa_lab for GitLab

# GITHUB
Host github.com
   HostName github.com
   PreferredAuthentications publickey
   IdentityFile ~/.ssh/id_rsa_hub

# GITLAB
Host gitlab.com
   HostName gitlab.com
   PreferredAuthentications publickey
   IdentityFile ~/.ssh/id_rsa_lab
Fatema Tuz Zuhora
  • 3,088
  • 1
  • 21
  • 33
1

Try generating on Windows an SSH key with the legacy format, in case the new OpenSSH one isn't fully recognized, using -m PEM:

ssh-keygen -m PEM -t rsa -P "" -f /c/Users/<yourLogin>/.ssh/id_rsa_hub
ssh-keygen -m PEM -t rsa -P "" -f /c/Users/<yourLogin>/.ssh/id_rsa_lab

Then declare your two keys in a ~/.ssh/config file:

Host gh
 HostName github.com
 User git
 IdentityFile /c/Users/<yourLogin>/.ssh/id_rsa_hub  

Host gl
 HostName gitlab.com
 User git
 IdentityFile /c/Users/<yourLogin>/.ssh/id_rsa_lab  

Host *
  PreferredAuthentications publickey

Your SSH URL will be gh:<user>/<repo> or gl:<user>/<repo>

phd
  • 82,685
  • 13
  • 120
  • 165
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250