如何解决在使用 SSH 连接到 EC2 Linux 实例时出现的错误“无法协商: 找不到匹配的主机密钥类型”?
在使用 SSH 连接到 Amazon Elastic Compute Cloud(Amazon EC2)Linux 实例时,我收到了“找不到匹配的主机密钥类型”或“找不到匹配的密钥交换方法”错误。简短描述
简短描述
在使用 SSH 连接到 EC2 Linux 实例时,您可能会看到以下错误之一:
更新 openssh-client
旧版本的 openssh-client 可能不支持由服务器协商的密钥交换算法。请运行以下命令之一,以便将客户端更新到最新版本:
Ubuntu 和 Debian
sudo apt upgrade openssh-client
Amazon Linux、RHEL、Fedora
sudo yum upgrade openssh-clients
解决“找不到匹配的主机密钥类型”错误
Unable to negotiate with X.X.X.X port 22. no matching host key type found. Their offer: rsa-sha2-512,rsa-sha2-256,ecdsa-sha2-nistp256,ssh-ed25519.
要解决此错误,请确保服务器和客户端至少有一个匹配的主机密钥算法。在服务器和客户端运行以下命令,以检查主机密钥算法:
sudo ssh -Q key
要在客户端上添加其他算法,请在 ~/.ssh/config 或 /etc/ssh/ssh_config 文件中附加以下行:
vi ~/.ssh/config HostkeyAlgorithms +ssh-ed25519
解决“找不到匹配的密钥交换方法”错误
Unable to negotiate with X.X.X.X port 22: no matching key exchange method found. Their offer: curve25519-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha25
要解决此错误,请确保服务器和客户端至少有一个匹配的密钥交换算法。在服务器和客户端上运行以下命令,以检查密钥交换算法: