【问题标题】:What is wrong with gitlab and ssh keysgitlab 和 ssh 密钥有什么问题
【发布时间】:2020-08-06 17:45:20
【问题描述】:

Gitlab 和 ssh 密钥有一些奇怪的问题。 我做的是

  1. 创建了一对 rsa 密钥
  2. id_rsa_GitLab
  3. id_rsa_GitLab.pub
  4. 将公钥添加到我的 gitlab 帐户中
  5. 尝试验证 ssh 是否能够连接 ssh -Tvvv git@xxxx.xx

这样做时,我得到了这个输出

$ ssh -Tvvv git@xxxx.xx
OpenSSH_8.3p1, OpenSSL 1.1.1g  21 Apr 2020
debug1: Reading configuration data /c/Users/Ulrich Waibel/.ssh/config
debug1: /c/Users/Ulrich Waibel/.ssh/config line 2: Applying options for xxxx.xx
debug1: Reading configuration data /etc/ssh/ssh_config
debug2: resolving "xxxx.xx" port 22
debug2: ssh_connect_direct
debug1: Connecting to xxxx.xx [xxx.xxx.xxx.153] port 22.
debug1: Connection established.
debug1: identity file /c/Users/Ulrich Waibel/.ssh/id_rsa_GitLab type 0
debug1: identity file /c/Users/Ulrich Waibel/.ssh/id_rsa_GitLab-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.3
debug1: Remote protocol version 2.0, remote software version mod_sftp
debug1: no match: mod_sftp
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to xxxx.xx:22 as 'git'
debug3: send packet: type 20
debug1: SSH2_MSG_KEXINIT sent
debug3: receive packet: type 20
debug1: SSH2_MSG_KEXINIT received
debug2: local client KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,ext-info-c
debug2: host key algorithms: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,sk-ecdsa-sha2-nistp256-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,sk-ssh-ed25519-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ecdsa-sha2-nistp256@openssh.com,ssh-ed25519,sk-ssh-ed25519@openssh.com,rsa-sha2-512,rsa-sha2-256,ssh-rsa
debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,3des-cbc,aes256-cbc,aes192-cbc
debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,3des-cbc,aes256-cbc,aes192-cbc
debug2: MACs ctos: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: none,zlib@openssh.com,zlib
debug2: compression stoc: none,zlib@openssh.com,zlib
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug2: peer server KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256
debug2: host key algorithms: ssh-rsa
debug2: ciphers ctos: aes192-ctr,aes256-ctr,aes128-ctr,aes192-cbc,aes256-cbc,aes128-cbc
debug2: ciphers stoc: aes192-ctr,aes256-ctr,aes128-ctr,aes192-cbc,aes256-cbc,aes128-cbc
debug2: MACs ctos: hmac-sha2-512,hmac-sha2-256,hmac-sha1
debug2: MACs stoc: hmac-sha2-512,hmac-sha2-256,hmac-sha1
debug2: compression ctos: none
debug2: compression stoc: none
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ssh-rsa
debug1: kex: server->client cipher: aes128-ctr MAC: hmac-sha2-256 compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: hmac-sha2-256 compression: none
debug3: send packet: type 30
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug3: receive packet: type 31
debug1: Server host key: ssh-rsa SHA256:jQZlCRVqhjK3w3CQWwpfbsUQaZxL5CGV1wYazbGUc7M
The authenticity of host 'xxxx.xx (xxx.xxx.xxx.153)' can't be established.
RSA key fingerprint is SHA256:jQZlCRVqhjK3w3CQWwpfbsUQaZxL5CGV1wYazbGUc7M.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'xxxx.xx,xxx.xxx.xxx.153' (RSA) to the list of known hosts.
debug3: send packet: type 21
debug2: set_newkeys: mode 1
debug1: rekey out after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug3: receive packet: type 21
debug1: SSH2_MSG_NEWKEYS received
debug2: set_newkeys: mode 0
debug1: rekey in after 4294967296 blocks
debug1: Will attempt key: /c/Users/Ulrich Waibel/.ssh/id_rsa_GitLab RSA SHA256:1vaiihW8GNAzlMgDsoScFqMmxFw3FHScM1x30NboJZw explicit
debug2: pubkey_prepare: done
debug3: send packet: type 5
debug3: receive packet: type 6
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug3: send packet: type 50
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,password
debug3: start over, passed a different list publickey,password
debug3: preferred publickey
debug3: authmethod_lookup publickey
debug3: remaining preferred:
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /c/Users/Ulrich Waibel/.ssh/id_rsa_GitLab RSA SHA256:1vaiihW8GNAzlMgDsoScFqMmxFw3FHScM1x30NboJZw explicit
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,password
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
git@xxxx.xx: Permission denied (publickey,password).

我使用的是 Windows 10,git v2.28.0.windows.1 用 git-bash 创建了密钥,还用 git-bash 做了 ssh -T 所有文件都位于 $ser$.ssh 还有一个包含此内容的配置文件

# GitLab.com
Host xxxx.xx
   Preferredauthentications publickey
   IdentityFile"/c/users/Ulrich Waibel/.ssh/id_rsa_GitLab"

感谢任何帮助

【问题讨论】:

    标签: ssh gitlab git-bash


    【解决方案1】:

    尝试使用以下 %USERPROFILE%.ssh\config 文件(确保 eol 行尾是 LF,而不是 CRLF)

    # GitLab.com
    Host xxxx.xx
       Hostname <correct.hostname>
       Preferredauthentications publickey
       IdentityFile "/c/users/Ulrich Waibel/.ssh/id_rsa_GitLab"
       User git
    

    # GitLab.com
    Host xxxx.xx
       Hostname <correct.hostname>
       Preferredauthentications publickey
       IdentityFile C:\users\Ulrich Waibel\.ssh\id_rsa_GitLab
       User git
    

    # GitLab.com
    Host xxxx.xx
       Hostname <correct.hostname>
       Preferredauthentications publickey
       IdentityFile "C:\users\Ulrich Waibel\.ssh\id_rsa_GitLab"
       User git
    

    你错过了Hostname gitlab.com
    既然可以加User git,那么测试就变成了:

    ssh -Tv xxxx.xx
    

    OP Ulithe comment 中确认:Host 条目的“&lt;correct.hostname&gt;”中有错字

    【讨论】:

    • 感谢您的回复。我将主机名更改为我的 gitlab 实例(我们在自己的主机上运行 gitlab on-prem)并按照您的建议设置用户。在我的配置文件中,我有第二个连接到我的私人 github 帐户,它工作正常。与我的私人 GitLab 帐户的连接也可以正常工作。只有针对我们自己的主机的身份验证不起作用。我创建了一个新的 ssh 密钥并替换了现有的,但这没有帮助。
    • 遇到了问题。添加主机名属性后,我在主机名值中输入了一个错字。修复此问题后,它工作正常
    猜你喜欢
    • 2020-03-01
    • 2014-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-30
    • 1970-01-01
    • 2022-09-23
    相关资源
    最近更新 更多