Issue
I'm trying to configure git so I don't have to keep authenticating (and also learn a bit more about git).
I had previously been using password-based authentication, which is repetitive to keep typing in my passwords. I followed the steps (using windows) to set up SSH keys in github. I gave my key a specific name, anticipating that I will need more than one SSH key at some point. It doesn't make sense to always have id_rsa
for github! I received the email that the key was successfully created, and I used git bash (because windows) to start the SSH client silently and added my private key. But running a git clone
gave me this error:
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I then had the idea to try it with the default name (id_rsa
), rather than my custom name, and of course it works. So my question is how do I avoid this? I don't want the default name to be reserved for github.
Solution
You can set up an ssh configuration file to tell the ssh
command to use that specific key when connecting to github.
Create the file .ssh/config
with the content:
Host github.com
IdentityFile ~/.ssh/github_rsa_key
Assuming that you've named your private key ~/.ssh/github_rsa_key
.
Now try connecting to github:
$ ssh [email protected]
You should see:
Hi <your github username>! You've successfully authenticated, but GitHub does not provide shell access.
Answered By - larsks Answer Checked By - Katrina (WPSolving Volunteer)