Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gitlab deploy keys configured but still doesn't grant access

I just configured Gitlab with a deploy key so that it doesn't ask for a username and password every time—but when pulling, it still fails with the following error:

[email protected]: Permission denied (publickey, keyboard-interactive).
fatal: Could not read from remote repository.

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

What I did so far is this:

  1. Generated the SSH key that can be found under ~/.ssh/
  2. Copied and pasted id_rsa.pub in the Gitlab deploy keys section
  3. Added the key to the SSH registery with ssh-add ~/.ssh/id_rsa
  4. Setup a config file under ~/.ssh with following contents:
    Host gitlab.co
    RSAAuthentication yes
    IdentityFile ~/.ssh/id_rsa
    
  5. Changed the git remote from the one using HTTPs to the one using SSH.

I searched both Google and StackOverflow for a possible solution, but didn't find any similar discussion. Any ideas what I may be missing?

like image 821
Ivica Pesovski Avatar asked Oct 27 '25 11:10

Ivica Pesovski


1 Answers

I was using sudo to do git pull, which resulted in the server trying to authenticate with the sudo user's SSH key.

I fixed it by changing the owner of the .git directory to be my logged-in user, meaning this command:

sudo chown -R ubuntu:ubuntu .git

After this, it all worked fine.

I believe this is a common scenario and I am now surprised I couldn't find more info about this.

like image 165
Ivica Pesovski Avatar answered Oct 29 '25 02:10

Ivica Pesovski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!