2

I have a new system (MacBook Pro) and want to set it up such that it can directly push to my remote repository on GitHub. The steps I followed were:

  1. Generated an ssh key using the command ssh-keygen -t rsa.
  2. Copied the content from id_rsa.pub into the SSH key area of my Github account.
  3. Created a repository on GitHub.
  4. Copied the repository url (https) into my existing local project using git remote set-url origin https://github.com/username/repo.git.
  5. Took a pull using git pull origin master (which worked without errors).
  6. While pushing the new changes using git push origin master I got the below error.
remote: Permission to UserName/repo-name.git denied to name.
fatal: unable to access 'https://github.com/UserName/repo-name.git/': The requested URL returned error: 403

Question:
1. Why am I getting the permissions denied error even after adding the SSH key to Github? Shouldn't GitHub consider my system to be trusted device after adding an SSH key?
2. How do I add my system as a trusted device so that I don't get the permissions denied error?

NigelDcruz
  • 897
  • 8
  • 18

2 Answers2

4
  1. Why am I getting the permissions denied error even after adding the SSH key to Github?

Because you are using an SSH key, which has nothing to do with HTTPS authentication (based on username/password)

How do I add my system as a trusted device so that I don't get the permissions denied error?

Either set the proper SSH URL

git remote set-url origin git@github.com:USERNAME/REPOSITORY.git
           ^^^^^^^

This is case sensitive, and the username must be the GitHub one, where your repo resides.
It has nothing to do with git config user.name/user.email (which are not used at all for authentication, only for commit authorship)

Or you keep your current HTTPS URL, but you check if you have a credential manager caching wrong credentials:

git config credential.helper

For instance, for a manager one, you can reject old /fill new credentials (GitHub Username/password) associated to github.com.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

You set the origin to https using an ssh configuration. Try to set your remote to ssh instead:

git remote set-url git@github.com:USERNAME/REPOSITORY.git
AElMehdi
  • 572
  • 4
  • 12
  • I've tried the above and it didn't work. The permission denied error is still there. – NigelDcruz Sep 26 '19 at 18:38
  • Did you set your user and email in the git configuration? – AElMehdi Sep 26 '19 at 18:41
  • Yes. Using the following: git config --global user.name "FIRST_NAME LAST_NAME" and git config --global user.email "MY_NAME@example.com" – NigelDcruz Sep 26 '19 at 18:43
  • Then you can check your ssh connection following this guide: https://help.github.com/en/articles/testing-your-ssh-connection. – AElMehdi Sep 26 '19 at 18:48
  • I followed the guide and ended up with this: "Hi username! You've successfully authenticated, but GitHub does not provide shell access." – NigelDcruz Sep 26 '19 at 19:03
  • Cool! Did your retry to push? – AElMehdi Sep 26 '19 at 19:08
  • There must be a typo somewhere, I suggest you to redo the whole process following [the official guide](https://help.github.com/en/enterprise/2.15/user/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent) (I don't know which steps you've followed!) – AElMehdi Sep 26 '19 at 19:15