ziiweb ziiweb - 1 month ago 20
Git Question

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 user.name "Your Name"
git config --global user.email tirenga@gmail.com
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 git@github.com:tirenga/tirenga.git
git push origin master


But I get this error:


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

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 a superuser will not work with the same public key as running a command as user. Therefore github refused the connection.)

This solutionr requires a SSH key already to be set up: https://help.github.com/articles/generating-ssh-keys