GitHub - Resolving Error response from daemon: Head : unauthorized

Problem Statement

You get an unathorized error when trying to pull an image from GitHub.

This generally happens because you either don't have a GitHub token set up, or your token doesn't have the right permissions.

Install and setup the GitHub CLI

While you can setup a GitHub token manually by going to https://github.com/settings/tokens?type=beta, I prefer to just use the gh auth token feature of the GitHub CLI.

Setup GitHub CLI

  1. Install the GitHub CLI using the instructions here.
  2. Login using github auth login and follow the instructions in your terminal to authenticate in your browser using the one-time code that will appear
    gh auth login
    
  3. Verify you're successfully logged in with gh auth status. You should see something like:
    gh auth status
    
    
     ➜ gh auth status
    
     github.com
     
     ✓ Logged in to github.com account mbuotidem (keyring)
    
     \- Active account: true
    
     \- Git operations protocol: ssh
    
     \- Token: gho_************************************
    
     \- Token scopes: 'admin:public_key', 'gist', 'read:org', 'repo'
    
     

Grant yourself the packages read scope

  1. Run gh auth refresh passing in the desired scope. Follow the instructions in your terminal to authenticate in your browser using the one-time code that will appear
    gh auth refresh --scopes read:packages
    

Docker login and try to pull again

  1. Pipe the auth token into the docker login command - make sure to replace mbuotidem with your GitHub username
    gh auth token | docker login ghcr.io -u mbuotidem --password-stdin
    
  2. You can now pull the image
    docker pull ghcr.io/mbuotidem/mbuotidem.github.io:main  
    

If you need to grant yourself other scopes, learn more about available scopes here To learn more about available GitHub CLI commands, go here