Sub topic 1
What GitHub authenticates, and what it authorizes
Prerequisites
This chapter assumes you can clone, commit, push, and pull with Git. You should be comfortable in a terminal and have a GitHub account. You should also know that a remote is a copy of your repository hosted elsewhere, such as on GitHub.
Two questions GitHub asks
Every time Git talks to a private repository on GitHub, GitHub has to answer two separate questions.
- Authentication: who are you? You prove an identity with a credential, such as a personal access token or an SSH key.
- Authorization: what are you allowed to do? GitHub checks the permissions that identity holds on the repository, and the limits attached to the credential itself.
The two checks run in this order. If authentication fails, GitHub never reaches the permission check.
Why the difference matters
A valid credential does not grant access by itself. Suppose you authenticate as yourself with a working SSH key and then push to a repository where you only have read access. GitHub knows who you are, so authentication succeeds. It then refuses the push because you are not authorized to write.
The reverse also happens. If your token has expired, you may have full write access to the repository, but GitHub still cannot tell who you are. The request fails at the first check.
Authorization has two layers:
- Your account permissions on the repository or organization, such as read, write, or admin.
- The limits on the credential. A token can carry fewer permissions than your account. A deploy key is tied to one repository. Organizations that use SAML single sign-on can also require you to authorize a credential before it works there.
The effective access is the overlap of the two layers. A credential never gives you more than your account has.
Reading the error messages
The wording of a failure tells you which check failed. This helps when you troubleshoot later.
| Message | Likely stage | Meaning |
|---|---|---|
| `Permission denied (publickey)` | Authentication | GitHub did not accept any SSH key you offered. |
| `Authentication failed` or `Invalid username or token` | Authentication | The HTTPS credential is wrong, expired, or revoked. |
| `Permission to OWNER/REPO.git denied to USER` | Authorization | GitHub knows who you are, but that account cannot write here. |
| `Repository not found` | Either | GitHub hides private repositories from identities that cannot see them. |
The last row is a common trap. A private repository you cannot access returns "not found" instead of "forbidden", so a typo and a permissions problem look the same. Check the URL first, then check which account Git is using.
What comes next
GitHub offers two main ways to authenticate Git. HTTPS remotes use a username and a personal access token. SSH remotes use a key pair. The next chapters cover how to tell the two apart and how to set up each one.
Exercise
You push to a repository and see "Permission to acme/tools.git denied to alice." Your SSH key is loaded and ssh -T [email protected] greets you as alice. Did authentication or authorization fail, and what is the likely cause?
Show answer
Authorization failed. GitHub authenticated you as alice, which is why the greeting works. The account alice lacks write permission on acme/tools. The fix is to get write access from the repository owner, not to change keys.