Solve ‘git push Permission denied (publickey)’
It has been more than a year since I last updated GitHub. When I pushed changes to remote repo, I got error:
git push -u origin master
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.and after some time, I found that it was because the SSH key had expired.
The solution is as follows if you already set SSH key in your device.1 Run in command line(git bash window):
ls -al ~/.ssh # check if you set SSH keywhich should shows several files including id_rsa and id_rsa.pub. Then run:
cat ~/.ssh/id_rsa.pubcopy the contents starting from ssh-rsa and paste it into your GitHub SSH keys setting.
If both your device and GitHub account have the SSH key but your permissioin was denied, then try the solution below:
ssh-agent bash
ssh-add ~/.ssh/id_rsawhich might work.2