Ssh Clone Not Working with Github

Ssh Clone Not Working with Github

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
  • git clone git://

But when I tried git clone :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 , 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?

3

7 Answers

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.

5

You can either follow the below document to add your key to ssh-agent

or you can run the following command to execute it temporarily

ssh-agent bash -c 'ssh-add ~/.ssh/github_rsa; git clone git://

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.

1

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.

Actually first you should do generate ssh keys and then save them in your account.

See the following link for more details

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.

1

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
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

David Miller
Author

David Miller

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.