Github authenticates but will not allow code push

It's a silly mistake I did and the fix is simple. Just delete the deploy key, add the same private key or new private key again, and this time, just don't forget to mark the "Allow write access" option.

Just don't forget to mark this when adding a new SSH key in github


The error:

ERROR: The key you are authenticating with has been marked as read only.

could mean that either you:

  • you're trying to push to repo by using key which was associated with another repository (e.g. as deploy key), so check by:

    $ ssh -i ~/.ssh/id_rsa [email protected]
    Hi user/project! You've successfully authenticated, but GitHub does not provide shell access.
    

    And compare user/project if it's the same as your repository where you want to push.

  • your key has been locked (e.g. it wasn't used for a long time), so you've to re-confirm it by completing the audit of your existing ssh keys at your GitHub user profile (/settings/ssh),

  • you're using multiple keys at the same time, check by: ssh-add -l (if so, remove them and re-add the right one again).

So:

Please make sure you have the correct access rights and the repository exists.

by the following simple steps:

  1. Note your RSA fingerprint by:

    $ ssh-add -l
    2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx (stdin) (RSA)
    
  2. Then check at GitHub if it has been added into your account or repository:

    • for account, check at: /settings/ssh (SSH keys),

      • if missing, please add it,
      • if Key is already in use, find which other repo using it (see below), then remove and re-add in your account,
    • for specific repository, check at: :name/:repo/settings/keys (Deploy keys),

    • if you're not repository owner, check if you're in the right group (with push access).

Alternatively use & add new key, troubleshoot common SSH Problems or contact GitHub support, as they could revoked it for some reason (e.g. by publicly disclosing it).


It seems likely that you have more than one SSH key, and the key that's being presented is a deploy key for the repository rather than one of your account's keys with write permissions. There are two ways of dealing with this:

  1. Remove all keys from your SSH agent, and re-add just the correct account key.

    ssh-add -D
    ssh-add /path/to/correct/key
    
  2. Use HTTPS instead of SSH. You can do this easily by changing the remote URL for origin to use the HTTPS scheme instead of SSH.

One or the other of these should work, unless you are simply presenting the wrong credentials altogether.

Tags:

Git

Github