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

 2022年11月11日 分类:前端设计  评论(0)  阅读(417)

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

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 服务器。

在终端中运行命令:

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 服务器。

在终端中运行命令:

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

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

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

查看后发现代码如下:

#	$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目录下找到,我们添加如下代码:

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

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

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

wechat_app
微信公众号:webapp_club
关注一下,或许能让你获得更多前端咨询信息。
加载中...
分享中心
各类业务开发,联系QQ:5679361
广告位联系QQ:5679361

评论 抢沙发

评论前必须登录


如果你觉得本站内容对你有所帮助,比如提升你对编程方面的认识,你可以通过上面的二维码请博主喝杯咖啡,安好。

WEB前端开发部落(公众号:webapp_club)

群列表

前端初级学习群:初级Web前端学习群(后期为支付入群)
PHP初级学习群:PHP(MySQL)学习交流群
QQ群仅作为相关领域讨论平台,均提供高质量问题交流,禁止闲聊,无法接受的朋友请勿加群!
进群需要通过这里获取进群码才能进群哦!