Reputation: 849
I am new to Git and GitHub.
I created a new repository and tried to clone on my local machine.
It worked for https and git-readonly URLs. That is, the following worked fine:
git clone https://github.com/npsabari/testrepo.git
git clone git://github.com/npsabari/testrepo.git
But when I tried git clone [email protected]:npsabari/testrepo.git
, it didn't work. It gave the following error message:
Cloning into 'testRepo'...
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
And then I tried ssh [email protected]
, but I got the error:
"Permission denied (publickey)."
instead of the welcome message.
What should I do to fix this? What is the reason for the error?
Upvotes: 31
Views: 123018
Reputation: 370
You can either follow the below document to add your key to ssh-agent
https://help.github.com/en/articles/connecting-to-github-with-ssh
or you can run the following command to execute it temporarily
ssh-agent bash -c 'ssh-add ~/.ssh/github_rsa; git clone git://github.com/npsabari/testrepo.git'
Upvotes: 8
Reputation: 8036
No reference can help me find a solution. After some late night research I found something that worked for me. So I shared if anyone needs and can save some time.
In your terminal run the following command:
ssh-keygen -t ed25519 -C "[email protected]"
You can skip adding any name, just press enter.
You can add passphrase or can skip (not recommended though)
Now you need to copy the code from the newly generated .pub key, to do that run the following code.
cat ~/.ssh/id_ed25519.pub
Login to Github.com, go to the setting page and then navigate to SSH and GPG keys
Click on New SSH key
Give any name and paste the code from .pub file and Save it.
Now you should git clone :)
Upvotes: 2
Reputation: 577
Quick solution for linux:
Run: find -al ~/.ssh
Copy the text inside of your "id_rsa.pub"
(if you do not have a ssh file then create one)
Go to your GitHub account and click on your profile picture in the top right corner. Select "Settings" from the drop-down menu.
In the left sidebar, click on "SSH and GPG keys."
Click on the "New SSH key" button.
Paste your public SSH key into the "Key" field.
Try to clone with SSH again
Upvotes: 2
Reputation: 3763
In my case, the problem was that the machine I was using was being authenticated by a repository rather than by my user, despite having a ssh key registered to my GitHub account.
You can check who is authenticated with
ssh -T [email protected]
This happened because I had a ssh key configured as Deploy Key to one of the repositories I was working on.
Upvotes: 7
Reputation: 548
There are two ways to clone.
1. SSH
2. HTTPS
In my case first one had given similar issue as you got, but then I tried using HTTPS
way by running following commands.
git clone https://xyz
Before that run this command git remote -v
. This should show
1. git-url(fetch)
2. git-url(push)
If you see these both upon running command, it tells you that you got push
right as well fetch
rights. After you have configured, and set proxy properly, if you still find problem, this solution I have explained should work. If your SSH public key and private key
are wrong then, you must fix that first before anything else.
Upvotes: 2
Reputation: 1160
I would like to add that if you need to use sudo
, it could interfere as the SSH key is not bound to that user. You might want to edit the rights before using git
rather then after.
Upvotes: 3
Reputation: 13231
I experienced this - only once ever - that the key generated by ssh-keygen
was broken. Checking the private and public key-files, they have the correct syntax, length, et.c.
It. Just. Didn't. Work.
On the same machine, I re-generated a key-pair. This finally let me connect to github via ssh.
Upvotes: 2
Reputation: 11132
The reason for the error is that you don't have your public key (~/.ssh/id_rsa.pub) uploaded to GitHub. Add it to your account(you may do this through the web panel provided by github) and it will work.
Upvotes: 4
Reputation: 21460
As per GitHub help, the error you're getting is related to wrong SSH configuration. Please follow indications for setting up SSH for GitHub and check accordingly.
Upvotes: 26
Reputation: 6404
Actually first you should do generate ssh keys and then save them in your account.
See the following link for more details
https://help.github.com/articles/generating-ssh-keys
Upvotes: 1