Pushing to GitHub Container Registry: unauthorized: unauthenticated: User cannot be authenticated with the token provided – Github

by
Ali Hasan
github github-container-registry

Quick Fix: Create a personal access token on GitHub , run the following command having username and PAT, docker login ghcr.io -u username -p ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

The Solutions:

Solution 1: Creating a Personal Access Token (PAT)

Steps:

  1. Visit GitHub’s token creation page at https://github.com/settings/tokens.
  2. Click on "Generate new token."
  3. Enter a token description and select "read/write packages" permissions.
  4. Click on "Generate token."
  5. Copy the generated PAT to your clipboard.

Solution 2: Using the PAT to Authenticate Docker

Steps:

  1. In your terminal, run the following command:
docker login ghcr.io -u username -p ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Replace "username" with your GitHub username and "ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" with the PAT you copied in the previous step.

Solution 3: Pushing the Image to GHCR

Now that Docker is authenticated with your PAT, you can push your image to GHCR using the following command:

docker push ghcr.io/username/imagename:latest

Q&A

How to solve ‘unauthorised: unauthenticated: User cannot be authenticated with the token provided’ when pushing to ghcr?

Create an access token (PAT), give docker permission to push to GHCR, then try push command again.