'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:
- Generated the SSH key that can be found under
~/.ssh/
- Copied and pasted
id_rsa.pub
in the Gitlab deploy keys section - Added the key to the SSH registery with
ssh-add ~/.ssh/id_rsa
- Setup a config file under
~/.ssh
with following contents:Host gitlab.co RSAAuthentication yes IdentityFile ~/.ssh/id_rsa
- 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?
Solution 1:[1]
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.
Solution 2:[2]
I have another situation, it runs well before, but in a few days I have not use the git pull, and today, it returns
root@api-test:~# git clone [email protected]:xxxx.git
Cloning into 'designcfg'...
[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.
when I tried.
And I change the .ssh/config from
Host gitlab
Hostname gitlab.com
IdentitiesOnly yes
IdentityFile ~/.ssh/xxx_rsa
to
Host gitlab.com
Hostname gitlab.com
IdentitiesOnly yes
IdentityFile ~/.ssh/xxx_rsa
It works again.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Jeremy Caney |
Solution 2 | Zagfai |