[英]Git clone with SSH in GitLab doesn't work
I have set my public ssh rsa key on my GitLab profile setting.我已经在我的 GitLab 配置文件设置中设置了我的公共 ssh rsa 密钥。 And on my remote server I already add my ssh private key with
在我的远程服务器上,我已经添加了我的 ssh 私钥
ssh-add ~/.ssh/id_rsa
In fact, when I run ssh connection verification on my remote server it is authenticated:实际上,当我在远程服务器上运行 ssh 连接验证时,它已通过身份验证:
user@some-remote-server:/var/www$ ssh -T git@gitlab.com
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 run git clone it said
fatal: Could not read from remote repository.
但是当我运行 git clone 时,它说
fatal: Could not read from remote repository.
user@some-remote-server:/var/www$ sudo git clone git@gitlab.com:repo/repo.git
Cloning into 'repo'...
git@gitlab.com: 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$
You are using sudo git clone
;您正在使用
sudo git clone
; that means you aren't using the same ssh-agent
than in your user.这意味着您没有使用与您的用户相同的
ssh-agent
。
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 do 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.我不知道您为什么要使用
sudo
权限执行git clone
,但是您需要使用sudo
(对于root
用户)启动您的代理并将私钥附加到它。
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
.此外,由于
sudo
禁用了环境变量, SSH_AGENT_PID
每次使用ssh
时都必须提供SSH_AUTH_SOCK
和SSH_AGENT_PID
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.