本站目前升级了全新主题zhime,该主题色彩更清新明亮。售价99元/套,你值得拥有,后台配置全,永久更新。另外还有Next.js版本!😃

git@e.coding.net: Permission denied (publickey). fatal: Could not read from remote repository.

今天装一台新电脑,然后重新拉了一下Git仓库代码,发现报错,很奇怪,错误如下:

code
git@e.coding.net: Permission denied (publickey). fatal: Could not read from remote repository.

网上搜了一下,发现应该是配置出了问题。

我个人的处理步骤如下:

1、首先,先检查自己生成的SSH公钥是否正确;

验证 SHA256 算法指纹

查看本地 .ssh/know_hosts 文件中关于 e.coding.net 的 SHA256 算法的指纹,如果返回值为 jok3FH7q5LJ6qvE7iPNehBgXRw51ErE77S0Dn+Vg/Ik,则证明您连接到了正确的 CODING 服务器。

在终端中运行命令:

code
copyssh-keygen -lf ~/.ssh/known_hosts

验证 MD5 算法指纹

查看本地 .ssh/know_hosts 文件中关于 e.coding.net 的 MD5 算法的指纹,如果返回值是 98:ab:2b:30:60:00:82:86:bb:85:db:87:22:c4:4f:b1,则证明您连接到了正确的 CODING 服务器。

在终端中运行命令:

code
ssh-keygen -E md5 -lf ~/.ssh/known_hosts

以上两种方式都可以验证你的算法指纹鉴权是否正常,当然了,我发现我的都是正常的,于是继续往下检查;

2、查看ssh_config文件里是否有配置相关属性(如果是单个仓库其实不会存在这些问题,但是如果多个仓库比如github/coding/gitee等就最好配置一下);

查看后发现代码如下:

code
#	$OpenBSD: ssh_config,v 1.35 2020/07/17 03:43:42 dtucker Exp $

# This is the ssh client system-wide configuration file.  See
# ssh_config(5) for more information.  This file provides defaults for
# users, and the values can be changed in per-user configuration files
# or on the command line.

# Configuration data is parsed as follows:
#  1. command line options
#  2. user-specific file
#  3. system-wide file
# Any configuration value is only changed the first time it is set.
# Thus, host-specific definitions should be at the beginning of the
# configuration file, and defaults at the end.

# Site-wide defaults for some commonly used options.  For a comprehensive
# list of available options, their meanings and defaults, please see the
# ssh_config(5) man page.

# Host *
#   ForwardAgent no
#   ForwardX11 no
#   PasswordAuthentication yes
#   HostbasedAuthentication no
#   GSSAPIAuthentication no
#   GSSAPIDelegateCredentials no
#   BatchMode no
#   CheckHostIP yes
#   AddressFamily any
#   ConnectTimeout 0
#   StrictHostKeyChecking ask
#   IdentityFile ~/.ssh/id_rsa
#   IdentityFile ~/.ssh/id_dsa
#   IdentityFile ~/.ssh/id_ecdsa
#   IdentityFile ~/.ssh/id_ed25519
#   Port 22
#   Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc
#   MACs hmac-md5,hmac-sha1,umac-64@openssh.com
#   EscapeChar ~
#   Tunnel no
#   TunnelDevice any:any
#   PermitLocalCommand no
#   VisualHostKey no
#   ProxyCommand ssh -q -W %h:%p gateway.example.com
#   RekeyLimit 1G 1h
#   UserKnownHostsFile ~/.ssh/known_hosts.d/%k
# Added by git-extra
Host ssh.dev.azure.com
	HostkeyAlgorithms +ssh-rsa
	PubkeyAcceptedAlgorithms +ssh-rsa
# Added by git-extra
Host *.visualstudio.com
	HostkeyAlgorithms +ssh-rsa
	PubkeyAcceptedAlgorithms +ssh-rsa

这是一个标准的配置文件,可以在git安装目录下的/etc/ssh目录下找到,我们添加如下代码:

code
Host *.coding.net
	HostkeyAlgorithms +ssh-rsa
	PubkeyAcceptedAlgorithms +ssh-rsa
	IdentityFile ~/.ssh/coding-rsa

上面代码中要注意IdentityFile 这个地址要连接到你安装的SSH公钥地址,一般默认是~/.ssh/id-rsa,因为我个人是使用多个,所以我改了名字的。

以上问题就完美解决,如果是Mac系统,需要搜索一下目录地址。

读完了点一下,作者能得积分

赞赏

如果这篇内容帮到了你,不妨请作者喝杯咖啡

分享 微博 QQ

发表评论

发表评论