项目实训 : gitlab 配置ssh key后不生效问题


title: gitlab 配置ssh key后不生效问题
tag: [Sdudoc, git, gitlab, ssh, ssh key]
category: 技术


描述

由于项目更换了远程仓库,从github迁移至gitlab,笔者于是新建了一个ssh key专门用于gitlab的认证,但是使用时却发现ssh key并没有生效。

笔者认为必须要搞清楚ssh认证期间发生了什么。

先尝试执行:

ssh -vvvT git@gitlab.swsdu.online

完整的DEBUG信息在附录中,这里截取一条重要信息:

debug1: Offering public key: /c/Users/11049/.ssh/id_rsa …

可以看到,认证时并没有用笔者新生成的sdudoc_gitlab密钥,而是之前的id_rsa

那么解决方法也就很明确了。

解决方法

在 ~/.ssh/ 下建立一个config文件,没有后缀,如果有的话直接进去修改

Host git.swsdu.online
	HostName git.swsdu.online
	IdentityFile ~/.ssh/sdudoc_gitlab
	PreferredAuthentications publickey
	
----
Host [ip 或 域名]
	HostName [ip 或 域名]
	IdentityFile ~/.ssh/[key name]
	PreferredAuthentications publickey

再次测试,通过

附录

失效时的DEBUG日志

debug1: Reading configuration data /etc/ssh/ssh_config
debug2: resolving “git.swsdu.online” port 22
debug2: ssh_connect_direct
debug1: Connecting to git.swsdu.online [121.250.213.219] port 22.
debug1: Connection established.
debug1: identity file /c/Users/11049/.ssh/id_rsa type 0
debug1: identity file /c/Users/11049/.ssh/id_rsa-cert type -1
debug1: identity file /c/Users/11049/.ssh/id_dsa type -1
debug1: identity file /c/Users/11049/.ssh/id_dsa-cert type -1
debug1: identity file /c/Users/11049/.ssh/id_ecdsa type -1
debug1: identity file /c/Users/11049/.ssh/id_ecdsa-cert type -1
debug1: identity file /c/Users/11049/.ssh/id_ecdsa_sk type -1
debug1: identity file /c/Users/11049/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /c/Users/11049/.ssh/id_ed25519 type -1
debug1: identity file /c/Users/11049/.ssh/id_ed25519-cert type -1
debug1: identity file /c/Users/11049/.ssh/id_ed25519_sk type -1
debug1: identity file /c/Users/11049/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /c/Users/11049/.ssh/id_xmss type -1
debug1: identity file /c/Users/11049/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.3
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.2p1 Ubuntu-4ubuntu0.3
debug1: match: OpenSSH_8.2p1 Ubuntu-4ubuntu0.3 pat OpenSSH* compat 0x04000000
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to git.swsdu.online:22 as ‘git’
debug3: hostkeys_foreach: reading file “/c/Users/11049/.ssh/known_hosts”
debug3: record_hostkey: found key type ECDSA in file /c/Users/11049/.ssh/known_hosts:8
debug3: load_hostkeys: loaded 1 keys from git.swsdu.online
debug3: order_hostkeyalgs: prefer hostkeyalgs: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
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,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,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,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,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
debug2: host key algorithms: rsa-sha2-512,rsa-sha2-256,ssh-rsa,ecdsa-sha2-nistp256,ssh-ed25519
debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
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
debug2: compression stoc: none,zlib@openssh.com
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: compression: none
debug3: send packet: type 30
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug3: receive packet: type 31
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:9ZgxICswo+e0UCYxwRpzi8MQFOXECeUn9tP23hxVztA
debug3: hostkeys_foreach: reading file “/c/Users/11049/.ssh/known_hosts”
debug3: record_hostkey: found key type ECDSA in file /c/Users/11049/.ssh/known_hosts:8
debug3: load_hostkeys: loaded 1 keys from git.swsdu.online
debug3: hostkeys_foreach: reading file “/c/Users/11049/.ssh/known_hosts”
debug3: record_hostkey: found key type ECDSA in file /c/Users/11049/.ssh/known_hosts:8
debug3: load_hostkeys: loaded 1 keys from 121.250.213.219
debug1: Host ‘git.swsdu.online’ is known and matches the ECDSA host key.
debug1: Found key in /c/Users/11049/.ssh/known_hosts:8
debug3: send packet: type 21
debug2: set_newkeys: mode 1
debug1: rekey out after 134217728 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 134217728 blocks
debug1: Will attempt key: /c/Users/11049/.ssh/id_rsa RSA SHA256:SXiMdbzwJse2yjl/7B2Sy+004be3e8TLrRLxVjqY3pA
debug1: Will attempt key: /c/Users/11049/.ssh/id_dsa
debug1: Will attempt key: /c/Users/11049/.ssh/id_ecdsa
debug1: Will attempt key: /c/Users/11049/.ssh/id_ecdsa_sk
debug1: Will attempt key: /c/Users/11049/.ssh/id_ed25519
debug1: Will attempt key: /c/Users/11049/.ssh/id_ed25519_sk
debug1: Will attempt key: /c/Users/11049/.ssh/id_xmss
debug2: pubkey_prepare: done
debug3: send packet: type 5
debug3: receive packet: type 7
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,sk-ssh-ed25519@openssh.com,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ecdsa-sha2-nistp256@openssh.com>
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,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /c/Users/11049/.ssh/id_rsa RSA SHA256:SXiMdbzwJse2yjl/7B2Sy+004be3e8TLrRLxVjqY3pA
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
debug1: Trying private key: /c/Users/11049/.ssh/id_dsa
debug3: no such identity: /c/Users/11049/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /c/Users/11049/.ssh/id_ecdsa
debug3: no such identity: /c/Users/11049/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /c/Users/11049/.ssh/id_ecdsa_sk
debug3: no such identity: /c/Users/11049/.ssh/id_ecdsa_sk: No such file or directory
debug1: Trying private key: /c/Users/11049/.ssh/id_ed25519
debug3: no such identity: /c/Users/11049/.ssh/id_ed25519: No such file or directory
debug1: Trying private key: /c/Users/11049/.ssh/id_ed25519_sk
debug3: no such identity: /c/Users/11049/.ssh/id_ed25519_sk: No such file or directory
debug1: Trying private key: /c/Users/11049/.ssh/id_xmss
debug3: no such identity: /c/Users/11049/.ssh/id_xmss: No such file or directory
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值