0

I created a repository on GitLab and I have a local project.

From: git remote -v I get:

origin  git@gitlab.com:projects/MyPrj.git (fetch)
origin  git@gitlab.com:projects/MyPrj.git (push)

When I try to push it to the repository with:

git push origin master

I get this error:

Permission denied (publickey).
fatal: Could not read from remote repository.

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

I can access the repository with a web browser, but not from git from the command line.

What am I doing wrong?

Pietro
  • 12,086
  • 26
  • 100
  • 193
  • If you're using SSH authentication, it might be worth trying HTTPS, to check if that's the issue. (I'm by no means a Git whiz, so I can't provide anything beyond passing that on). – Sean Apr 02 '18 at 00:26
  • Possible duplicate of [Git - Permission denied (publickey)](https://stackoverflow.com/questions/2643502/git-permission-denied-publickey) – phd Apr 02 '18 at 07:33
  • 1
    For me helps to change project path from `git@gitlab.com:...` to `https://gitlab.com/...` – chavy May 06 '20 at 20:48

1 Answers1

2

Check what is your remote URL associated with your local cloned repo:

cd /path/to/your/repo
git remote -v 

Depending on its scheme (https or ssh), you will need to make sure your authentication is correctly set.

  • https: you will need to enter your credentials once in order to cache them in the git credential helper (check what git config credential.helper returns)
  • ssh: make sure you have a /path/to/home/.ssh/id_rsa(.pub) files (public and private rsa SSH keys, with the public key content registered on your remote hosting service.

If this is SSH (on Linux), you need to follow "GitLab and SSH keys " and generate a new set of SSH keys with:

ssh-keygen -P "" -s -t rsa

Then copy the ~/.ssh/id_rsa.pub content on GitLab.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250