将其放在这里是为了尝试帮助其他可能遇到这个模糊问题的人。
我最近将 OSX 从 Mavericks 升级到了 El Capitan。然后我尝试登录之前登录过的系统,但 ssh 出现了以下错误:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:Btm9/3heWnRLKNiuhw4efh6sQWqCr/dNJUD87ejdR6k.
Please contact your system administrator.
Add correct host key in /Users/myuser/.ssh/known_hosts to get rid of this message.
Offending RSA key in /Users/myuser/.ssh/known_hosts:33
ECDSA host key for real.hostname.com has changed and you have requested strict checking.
Host key verification failed.
我查看了已知主机文件并看到了公钥:
real.hostname.com,192.168.0.138 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDHxFq6UNxndgThogOpKGYHK0HpmK1niGPBdNVyo9Q8zX//ms3joRH+tvL0RigJ+i5f0qSUjK2j80BYyCjnCXkYJ+YIPOGioGiuFGuoFutvJLH4iXT652b2WxJJwPqAvz70Xez1ToFxsIl8H0noUNTmlXRsfY0G5gX+089aghq3hH8OGUIGoyGCrv7Dpdh+tiMDXQqz0R4yhOa0iAojv+SVqbzArT8/AxC8VzuNDww6Fi96rxK1vaFg9SJEegwAZzWcbUFopA4cb8r7sQ5tHG56L5zX9/Yadg4/Pf02O6dP62M1rW7x6VoG/gEa72axqV/izm7/ws7SASsiKtHKRijf
然后我转到另一台机器,验证上面的密钥与另一台机器的 known_hosts 文件中的密钥匹配。然后我从另一台机器连接到 real.hostname.com,没有任何错误或警告。
为什么会发生这种情况?
答案1
这里的关键是从 Mavericks 升级到 El Capitan。事实证明,El Capitan 中的 ssh 客户端已升级,因此当它尝试连接到 ssh 服务器时,它现在使用不同的密钥类型,而不是“ssh-rsa”。
在这种情况下,ssh 尝试使用“ecdsa-sha2-nistp256”。在较新的系统上,如果您在域上运行“ssh-keyscan”,它将输出 ssh-rsa 密钥类型和 ecdsa-sha2-nistp256:
myname@myhost-1:~$ ssh-keyscan real.hostname.com
# real.hostname.com SSH-2.0-OpenSSH_6.6.1
real.hostname.com ecdsa-sha2-nistp256 k8DaAFOzRyv0kbP8Ua48IIk8DaAFOzRyvAAIbmlzdHAyNTYAAABBBAOq0InBTTdCqbaackF5biy0QghSFZBV/MRoL936yOAXgPAnZlHl+zQ5weK7nM2UNt2qGxqWKLSZ6gE6slZnQkw=
# real.hostname.com SSH-2.0-OpenSSH_6.6.1
real.hostname.com ssh-rsa k8DaAFOzRyv0kbP8Ua48IIk8DaAFOzRyvk8DaAFOzRyv0kbP8Ua48IIk8DaAFOzRyvFq6UNxndgThogOpKGYHK0HpmK1niGPBdNVyo9Q8zX//ms3joRH+tvL0RigJ+i5f0qSUjK2j80BYyCjnCXkYJ+k8DaAFOzRyv0kbP8Ua48IIiXT652b2WxJJwPqAvz70Xez1ToFxsIl8H0noUNTmlXRsfY0G5gX+HGXoLuLsr9VEghX2oyGCrv7Dpdh+tiMDXQqz0R4yhOa0iAojv+SVqbzArT8/AxC8VzuNDww6Fi96rxK1vaFg9SJEegwAZzWcbUFopA4cb8r7sQ5tHG56L5zX9/Yadg4/Pf02O6dP62M1rW7x6VoG/gEa72axqV/izm7/ws7SASsiKtHKRijf
当较新版本的 ssh 尝试将 ecdsa-sha2-nistp256 密钥类型字符串与 ssh-rsa 密钥类型字符串匹配时,它会失败,而不是识别它们是同一台机器的两种不同密钥类型。
我认为这是一个错误,但我不知道应该把它发布在哪里。