Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';t使用ssh密钥克隆Gitlab私有repo。密钥验证不需要';行不通_Git_Ssh_Gitlab_Ssh Keys - Fatal编程技术网

Can';t使用ssh密钥克隆Gitlab私有repo。密钥验证不需要';行不通

Can';t使用ssh密钥克隆Gitlab私有repo。密钥验证不需要';行不通,git,ssh,gitlab,ssh-keys,Git,Ssh,Gitlab,Ssh Keys,我在my.ssh下有默认密钥对,并在中添加了id_rsa.pub,但仍然无法使用此密钥访问gitlab ssh-vTgit@gitlab.com 无法登录: $ ssh -vT git@gitlab.com OpenSSH_7.9p1, LibreSSL 2.7.3 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 48: Applying options for * d

我在my.ssh下有默认密钥对,并在中添加了id_rsa.pub,但仍然无法使用此密钥访问gitlab

ssh-vTgit@gitlab.com

无法登录:

$ ssh -vT git@gitlab.com
OpenSSH_7.9p1, LibreSSL 2.7.3
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug1: Connecting to gitlab.com [35.231.145.151] port 22.
debug1: Connection established.
debug1: identity file /Users/denysobukhov/.ssh/id_rsa type 0
debug1: identity file /Users/denysobukhov/.ssh/id_rsa-cert type -1
debug1: identity file /Users/denysobukhov/.ssh/id_dsa type -1
debug1: identity file /Users/denysobukhov/.ssh/id_dsa-cert type -1
debug1: identity file /Users/denysobukhov/.ssh/id_ecdsa type -1
debug1: identity file /Users/denysobukhov/.ssh/id_ecdsa-cert type -1
debug1: identity file /Users/denysobukhov/.ssh/id_ed25519 type -1
debug1: identity file /Users/denysobukhov/.ssh/id_ed25519-cert type -1
debug1: identity file /Users/denysobukhov/.ssh/id_xmss type -1
debug1: identity file /Users/denysobukhov/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.9
debug1: Remote protocol version 2.0, remote software version ROSSSH
debug1: no match: ROSSSH
debug1: Authenticating to gitlab.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: diffie-hellman-group-exchange-sha256
debug1: kex: host key algorithm: ssh-rsa
debug1: kex: server->client cipher: aes128-ctr MAC: hmac-sha1 compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: hmac-sha1 compression: none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(2048<7680<8192) sent
debug1: got SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: got SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: ssh-rsa SHA256:pZaBIOeFjqundQMWm8JAamGIUe63cxi7G4ZTpGM5C+Y
debug1: Host 'gitlab.com' is known and matches the RSA host key.
debug1: Found key in /Users/denysobukhov/.ssh/known_hosts:19
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 4294967296 blocks
debug1: Will attempt key: /Users/denysobukhov/.ssh/id_rsa RSA SHA256:x3OEhLg/QPPUvr1f4IPo0+uHv8q73Da1TGjUnzD8FdQ
debug1: Will attempt key: /Users/denysobukhov/.ssh/id_dsa
debug1: Will attempt key: /Users/denysobukhov/.ssh/id_ecdsa
debug1: Will attempt key: /Users/denysobukhov/.ssh/id_ed25519
debug1: Will attempt key: /Users/denysobukhov/.ssh/id_xmss
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering public key: /Users/denysobukhov/.ssh/id_rsa RSA SHA256:x3OEhLg/QPPUvr1f4IPo0+uHv8q73Da1TGjUnzD8FdQ
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /Users/denysobukhov/.ssh/id_dsa
debug1: Trying private key: /Users/denysobukhov/.ssh/id_ecdsa
debug1: Trying private key: /Users/denysobukhov/.ssh/id_ed25519
debug1: Trying private key: /Users/denysobukhov/.ssh/id_xmss
debug1: Next authentication method: password
git@gitlab.com's password:
debug1: Authentications that can continue: password
debug1: Next authentication method: password
Permission denied, please try again.
git@gitlab.com's password:
我的配置

cat/etc/ssh/ssh\u配置

$ cat /etc/ssh/ssh_config
Host *
    SendEnv LANG LC_*
将以下内容添加到empty~/.ssh/config没有帮助:

Host gitlab.com
    Hostname gitlab.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa

为什么我的密钥不起作用?

最终找到了解决方案:生成一个新的ED25519 SSH密钥对

ssh-keygen -t ed25519 -C "email@example.com"
并将以下内容添加到~/.ssh/config中:

Host gitlab.com
  Hostname altssh.gitlab.com
  User git
  Port 443
  PreferredAuthentications publickey
还验证了~/.ssh/config修改是决定性的。

我在尝试从私有GitLab repos推/拉时遇到了类似的问题(通过谷歌发现)

git回购协议是使用HTTPS克隆的,例如
https://gitlab.com/user/repo.git
,然后再设置任何SSH密钥

为了使用SSH身份验证进行拉/推操作,即使在GitLab设置中设置了SSH密钥,也必须将远程URL更改为SSH版本
git@gitlab.com:user/repo.git

git remote set-url origin git@gitlab.com:user/repo.git
(假设您的遥控器称为原点。)


这可能只是必要的,但还不够,因为我尝试了很多其他方法,但没有在更改无法自行运行时重置更改。

根据调试跟踪,您的客户端向服务器提供了.ssh/id\u rsa,而服务器不接受它。有几件事可能导致这种情况。例如,您的id_rsa.pub文件可能与id_rsa文件不匹配,因此您使用错误的公钥设置了github。您是否可以执行
eval$(ssh agent-s)
,然后执行
ssh add~/.ssh/id_rsa
,然后重试?我记得那是以前为我做的。如果这不起作用,请尝试删除您的rsa密钥(如果您没有将其用于任何其他用途),然后从头开始。我将此密钥用于其他服务,无法删除它。我创建了一个自定义密钥:gitlab\u id\u rsa。添加:ssh add ~/.ssh/gitlab_id_rsa
$ssh add-l 4096 SHA256:BU0W1JRLgxvBPyXSYZ7qphRelLAECdDyvlAJndR1+4kdenys2@DENYSs-MacBook-Pro.local(RSA)2048 SHA256:x3OEhLg/QPPUvr1f4IPo0+uHv8q73Da1TGjUnzD8FdQdenys@DENYSs-MacBook-Pro.local(RSA)
Updated~/.ssh/config
IdentityFile~/.ssh/gitlab\u id\u rsa
它没有帮助。我的第二台电脑也有同样的问题。
git remote set-url origin git@gitlab.com:user/repo.git