Home > Net >  permission denied when pushing to github via git
permission denied when pushing to github via git

Time:10-20

this is the error:

git push origin master
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

The repo definitely exists as I pushed to it yesterday.

Things I tried:

  • copied my SSH public key to github settings several times
  • delete $HOME/.ssh and regenerated the SSH keys (ssh-keygen -t rsa -b 4096). I then copied the new public key to github.

some info

git remote -v
origin  [email protected]:myusername/myrepo.git (fetch)
origin  [email protected]:myusername/myrepo.git (push)

Any ideas why it could be failing? Thanks

CodePudding user response:

You'll need to debug your ssh connection to GitHub. See How can I run git push/pull commands with SSH verbose mode?

Once you have the debug output, stare closely at it to see which public key you're sending. The public key is how GitHub decide who you are, which in turn decides which repositories you can access. So if the public key you send on Tuesdays identifies you as frodo-baggins, while the public key you send on Fridays identifies you as sam-gamgee, you'll be able to enter Bag End freely on Tuesdays but only have access to Rosie on Fridays.

The order and values of public keys you send depends on a large number of ssh configuration knob settings, and also on your OS. Fortunately the debug output from ssh -v or ssh -vvv or whatever is pretty consistent across OSes, modulo things like path names.

CodePudding user response:

As long as ssh -Tv [email protected] does not display a welcome message with your GitHub account, your git push won't work.

> Hi USERNAME! You've successfully authenticated, but GitHub does not
> provide shell access.

Make sure to have set the right chmod permissions on:

  • $HOME: chmod 755 (or lower)
  • $HOME/.ssh: chmod 700 ~/.ssh
  • $HOME/.ssh/id-rsa: chmod 600 ~/.ssh/id_rsa
  • $HOME/.ssh/id-rsa.pub: chmod 600 ~/.ssh/id_rsa.pub

If you see a "too open" permission error, it means one of the parent folder of your key is writable for everybody, hence the importance of checking the permissions of $HOME, $HOME/ssh.

  • Related