Home/Troubleshooting/git push fails with Authentication failed or Permission denied (publickey) on a remote Mac

git push fails with Authentication failed or Permission denied (publickey) on a remote Mac

Updated · airankrush

Symptom

git push reports Authentication failed, remote: Invalid username or token, or Contact support: Permission denied (publickey). Cloning public repositories works, but pushing or accessing a private repository fails.

Possible causes (most common first)

  1. Over HTTPS, you entered your GitHub account password. GitHub no longer accepts passwords for git authentication; you need a personal access token or another method.
  2. The keychain holds a credential that has expired or belongs to another account, and git tries it automatically every time.
  3. Over SSH, no key has been generated on this Mac yet, or the public key has not been added to your GitHub account.
  4. The token's scope does not cover this repository, or you only have read access to it.

Troubleshooting steps (easiest first)

  1. First see which route you are on

    Run git remote -v in the repository folder. An address starting with https:// uses HTTPS and one starting with git@ uses SSH, and the two are debugged in completely different ways. GitHub is the example below; the reasoning is the same for other code platforms, and their own documentation has the specifics.

  2. HTTPS: use a token and clear old credentials

    When asked for a password, enter a personal access token, not your account password. If it fails with no prompt at all, the keychain holds an old credential. Following the GitHub documentation, open Keychain Access, search for github.com and delete the matching internet password entry; or run git credential-osxkeychain erase in Terminal, type host=github.com and protocol=https on separate lines, then press Return once more. Push again and enter the new token. GitHub itself recommends setting up SSH or using Git Credential Manager.

  3. SSH: check item by item

    Follow the order in GitHub's troubleshooting documentation: run ssh -T Contact support; on success it prints a greeting containing your username. The connecting user must be git, not your username. On failure, run ssh-add -l -E sha256 to see whether any key is loaded; no output means this machine has no usable key yet. ssh -vT Contact support shows which key files it actually tried. Finally, open the SSH and GPG keys page in GitHub settings and check that the public key fingerprint is in the list.

  4. Create a new key on this machine; do not copy your own

    We recommend generating a dedicated key on the remote Mac with ssh-keygen -t ed25519, adding the public key to your account and naming it so that it is clearly this rented machine. Do not copy the private key from your personal computer: a dedicated key can be deleted on its own when the rental ends or you suspect a leak, without affecting other devices. The same goes for tokens. Issue a separate token for this machine with the narrowest scope you can and an expiry date.

  5. Still rejected: check account and permissions

    If authentication passes but the push is rejected (a 403 or a no-permission message), the identity is fine; that identity has no write access to the repository, or the organisation requires the token to be authorised for single sign-on first. Use the greeting from ssh -T to confirm which account is in use. A common case is that the credential on the machine belongs to your other account.

When to contact support directly

Authentication is between you and the code platform. Support cannot see your tokens and keys, and should not. Only network-level symptoms need us: ssh -vT shows the connection timing out or being reset instead of being refused, or the browser cannot open the code platform either. Contact support on Contact support with your machine ID, when it happened and the command output with your username hidden. Do not change DNS or install proxy tools yourself for this. Before the rental ends, remember to delete this machine's public key and token on the platform.

FAQ

What does “do not run git with elevated privileges” mean?

GitHub's documentation says explicitly that git commands should not be run with administrator privilege elevation. With elevation, git reads another account's keys and configuration, cannot use the key you generated, and authentication fails as a result. It also leaves files with the wrong owner in the repository.

Pricing and availability: see the plans page · Help center (中文) · Refund policy (中文) · Telegram Contact support

Back to home · All troubleshooting pages