git push: permission denied (public key) git push: permission denied (public key) git git

git push: permission denied (public key)


I was facing same problem, here is what I did that worked for me.

Use ssh instead of http. Remove origin if its http.

git remote rm origin

Add ssh url

git remote add origin git@github.com:<username>/<repo>.git

Generate ssh key inside .ssh/ folder. It will ask for path and passphrase where you can just press enter and proceed.

cd ~/.sshssh-keygen

Copy the key. You can view your key using. If you hadn't specified a different path then this is the default one.

cat ~/.ssh/id_rsa.pub

Add this key to your github account. Next do

ssh -T git@github.com

You will get a welcome message in your console.

cd into to your project folder. git push -u origin master now works!


I just had to deal with this issue. @user3445140's answer helped me, but was much more than I needed to do.

  1. Get your public SSH key with cat ~/.ssh/id_rsa.pub
  2. Copy the key, including the "ssh-rsa" but excluding your computer name at the end
  3. Go to https://github.com/settings/ssh
  4. Add your SSH key


This worked for me.

first of all, remove current remote :

git remote rm origin

second, add remote through HTTPS but git@xxx :

git remote add origin https://github.com/Sesamzaad/NET.git

then push has worked for me :

git push origin master