I have set my public SSH RSA key on my GitLab profile setting. And on my remote server I already added my SSH private key with:
ssh-add ~/.ssh/id_rsa
In fact, when I run SSH connection verification on my remote server it is authenticated:
user@some-remote-server:/var/www$ ssh -T [email protected]
The authenticity of host 'gitlab.com (xxx.xx.xxx.xx)' can't be established.
ECDSA key fingerprint is SHA256:anmsdaskdnaslkdmaskd.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'gitlab.com,xxx.xx.xxx.xx' (ECDSA) to the list of known hosts.
Enter passphrase for key '/home/user/.ssh/id_rsa':
Welcome to GitLab, @alramdein!
user@some-remote-server:/var/www$
And I'm the owner of the repository. But when I ran Git clone it said fatal: Could not read from remote repository.
user@some-remote-server:/var/www$ sudo git clone [email protected]:repo/repo.git
Cloning into 'repo'...
[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.
user@some-remote-server:/var/www$
CodePudding user response:
You are using sudo git clone
; that means you aren't using the same ssh-agent
as in your user.
If you want to check that, you can just perform
ssh-add -L
and
sudo ssh-add -L
And you will see that there isn't the same agent in both accounts.
I don't know why you want to do git clone
with sudo
rights, but then you'll need to start your agent with sudo
(for the root
user) and attach the private key to it.
Also, since sudo
disables the environment variables, you'd have to provide the SSH_AUTH_SOCK
and the SSH_AGENT_PID
each time you use ssh
.