GitHub: Permission denied (publickey). fatal: The remote end hung up unexpectedly


I have followed these instructions below to upload a project.

Global setup:

 Download and install Git
  git config --global "Your Name"
  git config --global [email protected]
  Add your public key

Next steps:

  mkdir tirengarfio
  cd tirengarfio
  git init
  touch README
  git add README
  git commit -m 'first commit'
  git remote add origin [email protected]:tirenga/tirenga.git
  git push origin master

But I get this error:

Permission denied (publickey). fatal: The remote end hung up unexpectedly

10/24/2016 3:26:36 PM

Accepted Answer

For me the problem was the execution of clone via sudo.

If you clone to a directory where you have user permission ( /home/user/git) it will work fine.

(Explanation: Running a command as superuser will not work with the same public key as running a command as user. Therefore Github refused the connection.)

This solution requires a SSH key already to be set up:

1/13/2017 11:27:13 AM

Yes, It's a public key Problem. I'm a windows user,and the page below help me resolve this problem.

more precisely this link should be helpful


after you created the RSA key pair, you must to add it to SSH using:

ssh-add ~/.ssh/id_rsa

or wherever you created your rsa key pair.


Type the following command using your username and repository name:

git clone{user name}/{repo name}

in Ubuntu this works perfectly.


I got a solution after a long time in tutorials.

I followed the github tutorial on this link -> and I was able to connect in every step. But when I was trying to git push -u origin master I got this error:

Permission denied (publickey). fatal: Could not read from remote repository.

Please make sure you have the correct access rights

Thats how I`ve fixed it!! Go to the project directory using the Terminal and check it out

$git remote -v

You will get something like this:

origin  ssh://[email protected]/yourGithubUserName/yourRepo.git (fetch)
origin  ssh://[email protected]/yourGithubUserName/yourRepo.git (push)

If you are using anything different then [email protected], open the config file on git directory by typing the command:

vi .git/config

And configure the line

[remote "origin"]

url = ssh://[email protected]/yourGithubUserName/yourRepo.git

fetch = +refs/heads/*:refs/remotes/origin/

In my case, I had to setup the public key for another user, as I already had one for my main user. once I switched users and performed the commands in the link above I was able to perform the setup for my test server without a problem.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]