Cerin
Cerin

Reputation: 64739

Unable to push to Gitlab, You are not allowed to push code to this project

I recently became unable to push any changes to any of my repositories on Gitlab.com.

I know this sometimes happens if you've changed your SSH keys, or the site's down, but as far as I know, I haven't changed anything in my ~/.ssh directory, and Gitlab.com appears to be working.

Yet if I run git push I get the error:

You are not allowed to push code to this project.
fatal: Could not read from remote repository.

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

Oddly, git pull still works. I also tried re-cloning the repo, making and commit and pushing, but that still fails. Adding the --verbose option showed no further details.

I double checked that the SSH key on file in my Gitlab account matches the key on file in my ~/.ssh/id_rsa.pub file. I also tried adding the entry of my ~/.ssh/config:

Host gitlab.com
 IdentityFile ~/.ssh/id_rsa

but that had no effect.

What's going on here? Why is Gitlab suddenly not accepting the SSH key on file?

Upvotes: 5

Views: 12407

Answers (2)

keithpjolley
keithpjolley

Reputation: 2263

i've hit this problem by having multiple gitlab accounts, each with different ssh keys. its confusing to login to the website, create a project, make it world accessible, pull it down, and then not be able to push back up.

the problem was i had a second gitlab account with keys that showed up first in my key chain.

for instance, account1 is associated with ~/.ssh/id_rsa, account2 is associated with ~/.ssh/id_ed25519. i login to gitlab with account1, create and clone a repo and then can't push. the problem is that my ssh keychain had id_ed25519 first, so gitlab thinks account2 is trying to push the edits back up, which doesn't have permissions.

i noticed there was a feature request for the error message to be more verbose so that it would be easier to debug this problem. they said "good idea" then closed the request. :/

Upvotes: 3

VonC
VonC

Reputation: 1324228

Check first that the remote URL (git remote -v) is indeed an SSH one (git@gitlab:...), and not an HTTPS one (https://gitlab.com/...)

In the latter case (HTTPS), only your git config credential.helper could explain the error, having cached the wrong credentials (username/password for your GitLab account)

In case of the former, try and create a new SSH key with the old PEM format instead of the new OPENSSH one, in case that is better supported by GitLab.

Upvotes: 2

Related Questions