解决办法
如果最近升级到了 openssh 8.8 版,你会发现连接某些之前连接得好好的服务器突然无法连接:
Unable to negotiate with x.x.x.x port 2222: no matching host key type found. Their offer: ssh-rsa
解决办法是 ssh 命令指定算法:
ssh -o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa user@host -p 2222
上面比较麻烦,可以修改 ssh 配置文件 ~/.ssh/config
,对于无法成功连接的 host,增加以下配置项:
HostKeyAlgorithms +ssh-rsa
PubkeyAcceptedKeyTypes +ssh-rsa
完整的配置如下:
Host jump
Port 2222
HostName x.x.x.x
User ***
IdentityFile ~/.ssh/id_rsa
UseKeychain yes
AddKeysToAgent yes
PreferredAuthentications publickey
HostKeyAlgorithms +ssh-rsa
PubkeyAcceptedKeyTypes +ssh-rsa
问题原因
根据 OpenSSH 8.8 Release Notes 信息:
This release disables RSA signatures using the SHA-1 hash algorithm
by default. This change has been made as the SHA-1 hash algorithm is
cryptographically broken, and it is possible to create chosen-prefix
hash collisions for
从这里可以知道,从 openssh 8.8 版本开始默认禁用了 ssh-rsa 算法,对于大部分情况,这次的更改是无感知的,当服务器仅支持 ssh-rsa 算法时才会出现不兼容的情况。
本地启用 RSA/SHA1 支持仅仅只是一种权宜之计,官方建议是升级密钥算法或使用另一种密钥算法(例如 ECDSA 或 Ed25519 算法)。