我已将带有 Raspbian 操作系统的 Raspberry Pi 连接到本地网络,并使用 ssh 密钥设置 SSH 登录。我通过(为Raspberry Pi分配静态IP)成功登录ssh myname@192.168.5.163。
我现在已经删除了 Raspbian 操作系统,并插入了一张带有 Ubuntu Server(无头)的 SD 卡。
我打开树莓派并尝试登录,但出现错误:
ERROR: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
ERROR: @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
ERROR: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
ERROR: IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
ERROR: Someone could be eavesdropping on you right now (man-in-the-middle attack)!
ERROR: It is also possible that a host key has just been changed.
ERROR: The fingerprint for the ECDSA key sent by the remote host is
ERROR: SHA256:asfasfdasdfasfdasfdasdfasdfasdfasdfasfasdf.
ERROR: Please contact your system administrator.
ERROR: Add correct host key in /home/joedoe/.ssh/known_hosts to get rid of this message.
ERROR: Offending ECDSA key in /home/joedoe/.ssh/known_hosts:13
ERROR: remove with:
ERROR: ssh-keygen -f "/home/joedoe/.ssh/known_hosts" -R "192.168.5.163"
ERROR: ECDSA host key for 192.168.5.163 has changed and you have requested strict checking.
ERROR: Host key verification failed.
Run Code Online (Sandbox Code Playgroud)
我继续添加到我的.ssh/config:
host 192.168.5.163
StrictHostKeyChecking no
Run Code Online (Sandbox Code Playgroud)
但现在我明白了
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ 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:asdfasdfasdfasdfasdfasdfasdfasdfasdf.
Please contact your system administrator.
Add correct host key in /home/joedoe/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /home/joedoe/.ssh/known_hosts:13
remove with:
ssh-keygen -f "/home/joedoe/.ssh/known_hosts" -R "192.168.5.163"
Password authentication is disabled to avoid man-in-the-middle attacks.
Keyboard-interactive authentication is disabled to avoid man-in-the-middle attacks.
ubuntu@192.168.5.163: Permission denied (publickey,password).
Run Code Online (Sandbox Code Playgroud)
显然,问题是我想在同一 IP 地址上登录两个不同的操作系统,但新的 Ubuntu 操作系统不会更改 SSH 登录设置,并且不允许我以任何方式登录。
我应该如何操作才能交替使用这两种操作系统?
dav*_*dgo 30
您可以按照错误中的说明解决当前问题(每次切换盒子时都必须执行此操作)-
ssh-keygen -f "/home/joedoe/.ssh/known_hosts" -R "192.168.5.163"
Run Code Online (Sandbox Code Playgroud)
您遇到的问题是您的计算机检测到其登录的系统与之前看到的不同,并且出现警告是为了防止中间人攻击。
有多种方法可以正确处理这个问题。他们包括:
为每个框设置名称/etc/hosts,然后通过名称而不是 IP 引用 SSH 连接。通过这种方式,SSH 会将不同的服务器指纹与每个名称相关联。
忽略检查(这会让您面临中间人攻击,因此只有在您了解并愿意接受风险时才这样做。)您可以通过添加-o UserKnownHostsFile=/dev/null到 ssh 命令或-o StrictHostKeyChecking=no
2a. 您可以创建一个仅忽略一个 IP 的密钥检查的配置,方法是将以下内容放入~/.ssh/config
主机 192.168.5.163 StrictHostKeyChecking 否 UserKnownHostsFile=/dev/null
我不建议这样做,除非机器扮演相同的角色,但您可以在两台服务器(以及您更改的服务器上)/etc/ssh上设置相同的主机密钥。restart sshd这样,两台服务器对于客户端来说都是一样的。
小智 29
有几种潜在的解决方案。
最简单的解决方案是 davidgo 在他的回答中提出的一个解决方案,正如他提到的,这会让您容易遭受 MitM 攻击(不太可能,但即使在私人情况下,保持良好的安全性也很好)。
Host 192.168.5.163
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
Run Code Online (Sandbox Code Playgroud)
正如 Eugen Rieck 所提议的,一个稍微更好的解决方案是/etc/ssh/ssh_host_*key*在两个目标操作系统之间同步文件。
更可靠的方法是专门决定连接到哪个操作系统,因此如果连接到错误的操作系统,您确实会收到错误。例如,如果使用 ssh 的脚本针对错误的操作系统,那么它们就会失败。
您可以通过在~/.ssh/ssh_config.
Host raspbian-pi
Hostname 192.168.5.163
UserKnownHostsFile ~/.ssh/known_hosts_raspbian
Host centos-pi
Hostname 192.168.5.163
UserKnownHostsFile ~/.ssh/known_hosts_centos
Run Code Online (Sandbox Code Playgroud)
然后,您可以连接ssh <your_user>@raspbian-pi以检索 Raspbian OS 密钥,然后在 Raspberry Pi 上切换到 CentOS,执行相同的操作ssh <your_user>@centos-pi以获取 CentOS 密钥。然后,将来,每当您连接到错误的操作系统时,您都会收到主机密钥错误。确保第一次使用 SSH 命令时使用正确的操作系统,这样您就不会意外地将 CentOS 主机密钥存储在 Raspbian 已知主机文件中。
免责声明:我从未使用过此解决方案,也无法对其进行测试,但根据我的理解和 ssh 文档,它应该可以正常工作。
Eug*_*eck 21
最简单的方法是将/etc/ssh/ssh_host_*_key*一个安装复制到另一个安装 - 这将为两个操作系统提供相同的主机密钥,从而获得指纹。
另一种选择是为每个操作系统提供不同的 IP 地址。他们现在得到相同的地址,因为 DHCP 服务器看到相同的 MAC 地址。因此,您可以将一次安装配置为使用静态 IP 地址。
不过,我会遵循尤金的建议——这会让事情变得简单。或者获取第二个 Pi 并同时运行两台机器。