如何修复有关 ECDSA 主机密钥的警告

如何修复有关 ECDSA 主机密钥的警告

我正在尝试在 Ubuntu 服务器上设置无密码 SSH ssh-copy-id myuser@myserver,但出现了错误:

警告:'myserver' 的 ECDSA 主机密钥与 IP 地址 '192.168.1.123' 的密钥不同

是什么原因造成的?我该如何解决?我尝试删除.ssh远程计算机上的目录,然后ssh-keygen -R "myserver"在本地运行,但这并不能解决错误。

答案1

192.168.1.123删除本地机器上的缓存密钥:

ssh-keygen -R 192.168.1.123

答案2

就我而言,ssh-keygen -R ...没有修复警告。我有这样的额外信息:

Offending key for IP in /home/myuser/.ssh/known_hosts:8
Matching host key in /home/myuser/.ssh/known_hosts:24

我只是手动编辑~/.ssh/known_hosts并删除了第 8 行(“有问题的键”)。我尝试重新连接,主机已永久添加,之后一切都正常!

答案3

我在局域网计算机和我的两个网络托管帐户之间进行了大量 ssh 连接,因此我整理了 SSH 的各种零碎问题,包括使用身份验证问题ssh -v来查看哪里出了问题以及出了什么问题。

刚刚解决了这个问题,但对答案并不满意,我真的很想知道“为什么”......

我的情况的触发条件是:在工作中安装了新的服务器操作系统,在安装 openssh-server 包时,在工作服务器上生成了一组新的主机密钥。以前,我所有的服务器操作系统都是 Ubuntu,这次都改成了 Debian(我怀疑权限方面有细微的差别)。

当所有操作系统都是 Ubuntu 并且我重新安装服务器的操作系统时,在第一次通过 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 the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
06:ea:f1:f8:db:75:5c:0c:af:15:d7:99:2d:ef:08:2a.
Please contact your system administrator.
Add correct host key in /home/user/.ssh/known_hosts to get rid of this message.
Offending key in /home/user/.ssh/known_hosts:4
RSA host key for domain.com has changed and you have requested strict checking.
Host key verification failed.

然后我在计算机上打开~/.ssh/known_hosts启动 ssh,删除该行,重新连接,然后发生以下情况:

chris@home ~ $ ssh work
The authenticity of host '[work]:11122 ([99.85.243.208]:11122)' can't be established.
ECDSA key fingerprint is 56:6d:13:be:fe:a0:29:ca:53:da:23:d6:1d:36:dd:c5.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[work]:11122 ([99.85.243.208]:11122)' (ECDSA) to the list of known hosts.
Linux rock 3.2.0-4-amd64 #1 SMP Debian 3.2.51-1 x86_64

关于 :11122 的那部分是我在防火墙上路由 SSH 的端口号

我检查了以前的 Ubuntu 服务器的备份,并与新安装的 Debian 进行了比较:

Ubuntu:                                            Debian:
# Package generated configuration file             # Package generated configuration file
# See the sshd(8) manpage for details              # See the sshd_config(5) manpage for details

# What ports, IPs and protocols we listen for      # What ports, IPs and protocols we listen for
Port 22                                            Port 22
# Use these options to restrict which interface    # Use these options to restrict which interfaces
#ListenAddress ::                                  #ListenAddress ::
#ListenAddress 0.0.0.0                             #ListenAddress 0.0.0.0
Protocol 2                                         Protocol 2
# HostKeys for protocol version 2                  # HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key                  HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key                  HostKey /etc/ssh/ssh_host_dsa_key
------------------------------------------------   HostKey /etc/ssh/ssh_host_ecdsa_key
#Privilege Separation is turned on for security    #Privilege Separation is turned on for security
UsePrivilegeSeparation yes                         UsePrivilegeSeparation yes

所以是的,很可能主机最近开始使用 ecdsa 密钥,根据 Ubuntu 最近的变化,我认为这是更新造成的。Ubuntu 放弃了我所依赖的坚如磐石的 Linux 操作系统,这就是我这次安装 Debian 的原因。

我读过security.SE 关于 ecdsa 的问答并且已经从sshd_config我的新 Debian 服务器中删除了该行。(并运行service ssh restart

答案4

每次都会出现此提示,因为使用动态寻址时 IP 地址会不断变化。尽量使用静态 IP,这样您只需添加一次密钥。

相关内容