OpenSSH升级后Gitee不能使用密钥

2021年 10月 10日 星期日 22:58:37 CST 升级了我的办公电脑Dell Latitude3510 但是想在Gitee上添加日志时,发现不能使用密钥了。使用ssh命令测试,出现

1
git@gitee.com: Permission denied (publickey)

此问题第一次遇到,开始以为学校的网络问题,介理仔细排查后发现不是。经百度后找到一网站Fedora 33 - 快来升级你的SSH密钥啊,最终解决问题。此处为了方便的处理问题,精简后记录于此。

由于升级后OpenSSH版本太新,有一些协议变动导致出错,因为根据

1
$ ssh -vT git@gitee_key_one

给出的debug信息:no mutual signature algorithm (没有互签名算法), 作者使用谷歌到的内容为:

1
2
3
4
5
6
7
8
9
10
11
Future deprecation notice
=========================

It is now possible[1] to perform chosen-prefix attacks against the
SHA-1 hash algorithm for less than USD$50K. For this reason, we will
be disabling the "ssh-rsa" public key signature algorithm that depends
on SHA-1 by default in a near-future release.

This algorithm is unfortunately still used widely despite the
existence of better alternatives, being the only remaining public key
signature algorithm specified by the original SSH RFCs.

按其说法,SHA-1算法要收费,所以禁用ssh-rsa签名算法,所以得换一个签名算法。在gitee查询到他支持的签名算法:

1
支持以 'ssh-rsa', 'ssh-dss', 'ssh-ed25519', 'ecdsa-sha2-nistp256', 'ecdsa-sha2-nistp384' or 'ecdsa-sha2-nistp521' 开头

所以挑选一个除ssh-rsa之外的签名算法生成新的密钥,之后重新部署。即

1
ssh-keygen -t ed25519 -C "your_email@example.com"

将生成的公钥部署到gitee后,再修改本机的~/.ssh/config即可。另外硬要用过时的rsa时,执行如下命令也可以解决问题,即

1
ssh -o 'PubkeyAcceptedKeyTypes +ssh-rsa' hostname