共计 7825 个字符,预计需要花费 20 分钟才能阅读完成。
这篇文章主要为大家分析了如何解决 ssh 登陆问题的相关知识点,内容详细易懂,操作细节合理,具有一定参考价值。如果感兴趣的话,不妨跟着跟随丸趣 TV 小编一起来看看,下面跟着丸趣 TV 小编一起深入学习“如何解决 ssh 登陆问题”的知识吧。
1. 错误描述
当我想 ssh slave 节点时,出现如下错误
[cpp] view plain copy
hadoop@xuwei-laptop:~$ ssh slave
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: POSSIBLE DNS SPOOFING DETECTED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The RSA host key for slave has changed,
and the key for the corresponding IP address 192.168.0.42
is unchanged. This could either mean that
DNS SPOOFING is happening or the IP address for the host
and its host key have changed at the same time.
Offending key for IP in /home/hadoop/.ssh/known_hosts:9
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ 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
e1:e0:28:39:6d:fb:d6:45:72:71:c1:ec:3d:ef:78:19.
Please contact your system administrator.
Add correct host key in /home/hadoop/.ssh/known_hosts to get rid of this message.
Offending key in /home/hadoop/.ssh/known_hosts:5
RSA host key for slave has changed and you have requested strict checking.
Host key verification failed.
错误原因是因为我修改过 slave 节点。就是第一次我 ssh slave 节点的 ip 是 192.168.0.10,而第二次的时候 slave 的 ip 变为了 192.168.0.50. 这个时候我在使用 ssh slave 命令就会出现上述错误。
3. 问题解释
用 OpenSSH 的人都知 ssh 会把你每个你访问过计算机的公钥 (public key) 都记录在~/.ssh/known_hosts。当下次访问相同计算机时,OpenSSH 会核对公钥。如果公钥不同,OpenSSH 会发出警告,避免你受到 DNS Hijack 之类的攻击。因此我们现在只需要删除 knows_hosts 文件中所对应的 slave 节点的公钥,然后再 ssh slave 就可以了。我们使用命令
[cpp] view plain copy
sudo gedit known_hosts
打开 known_hosts,但是我们发现文件内的内容根本找不到 slave,文件内容如下
[cpp] view plain copy
|1|Xv9OoqvMzLO8ZB6RBgo5huXiJsM=|zwBphczddm/ogCsQfJJb8pO8CNo= ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA3fvljAowPKD9Lx4GkF75FQfj1edEPLTsY9TQv7S5mDS6RB8YvgP9SQxnqt0Dr+IpiDpRg6y7iv6Qm6WC4dOd4jJCPfbI4FUbGTkwLL4qeKo0+ZHZUS2ByeMd+PbqM0iIubKBsNBebA5c+RvqOCneYHOkrTKtwJsq2NnwhgFBz0odeFF7G7tBq6huK7KqikXZauEk7B4gnbtSiD2pG1XZzEUeXq8qEFLjWFPKBRYr8/AL/RZjktJRj98mCRtXCB9tef3DhFkHnXODfC/LzMX3vkQP2ahP4kbNmtXM8nkK2YFx0emAL07h76j89k9ByXzuN0mGw2QKcjFkDWNVkwk6CQ==
|1|peUXkOx+hnb6XQZZGGwMhOXAj04=|mqdXqRTi/MiqARL+dylDygmDgpk= ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA3fvljAowPKD9Lx4GkF75FQfj1edEPLTsY9TQv7S5mDS6RB8YvgP9SQxnqt0Dr+IpiDpRg6y7iv6Qm6WC4dOd4jJCPfbI4FUbGTkwLL4qeKo0+ZHZUS2ByeMd+PbqM0iIubKBsNBebA5c+RvqOCneYHOkrTKtwJsq2NnwhgFBz0odeFF7G7tBq6huK7KqikXZauEk7B4gnbtSiD2pG1XZzEUeXq8qEFLjWFPKBRYr8/AL/RZjktJRj98mCRtXCB9tef3DhFkHnXODfC/LzMX3vkQP2ah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h-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAs6IHrmuZwTilgYsOjwiOfQP1u1c3Aj6MH2EOaypGYxccDddcQu6QoKhVXQZWMZFt7W6MeZUa/QKqNVmcpho4NubyCpxfkBIybPzqbqQif8EmYrCCsbaU41hQppISrXNdlcn/S7TKM9T6sbQV1/moYScjQ4kEO+MchVmuIY5cm8kz5p8jxklSF2xFftB+kz7RmMJN3+GcGHOcgACngtxqFnqXfNF8RV1wv2lP5wLui7cv7V+pogExckzqiNfJMPnt8SCMvODHVMRnlJC5yOtpkDKH29X056KeYtK40KhMCQL9UMHfRPQgvQL0qArQ65RLevIckZ8YehOG9aCXbcWzBw==
|1|QLuhhDXvYoefLiZ7+fw5A9ErlV4=|bWOSl44257+rbK1Fn4zwMY8GE3c= ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAs6IHrmuZwTilgYsOjwiOfQP1u1c3Aj6MH2EOaypGYxccDddcQu6QoKhVXQZWMZFt7W6MeZUa/QKqNVmcpho4NubyCpxfkBIybPzqbqQif8EmYrCCsbaU41hQppISrXNdlcn/S7TKM9T6sbQV1/moYScjQ4kEO+MchVmuIY5cm8kz5p8jxklSF2xFftB+kz7RmMJN3+GcGHOcgACngtxqFnqXfNF8RV1wv2lP5wLui7cv7V+pogExckzqiNfJMPnt8SCMvODHVMRnlJC5yOtpkDKH29X056KeYtK40KhMCQL9UMHfRPQgvQL0qArQ65RLevIckZ8YehOG9aCXbcWzBw==
OpenSSH 在 4.0p1 引入了 Hash Known Hosts 功能,在 known_hosts 中把访问过的计算机名称或 IP 地址以 hash 方式存放,令入侵都不能直接知道你到访过那些计算机。这项新项功能 缺省是关闭的,要你手动地在 ssh_config 加上 \ HashKnownHosts yes\ 才会被开启。不过 Ubuntu 就缺省开启了个功能。
然而,偶然一些计算机的 ssh 公钥是合理地被更动。虽然遇到这些情况 OpenSSH 会发出惊告并禁止你进入该计算机。以往当我们确定该次 ssh 公钥被更动没有可疑时,我们用文字编辑器开启 known_hosts,把相关的公钥记录删掉就可以了。但现在因为所有计算机名称或 IP 地址都被 hash 了,我们很难知道那行是相关计算机的公钥。当然我们可以把整个 known_hosts 删除,但我们会同时失去其他正常计算机的 ssh 公钥。事实上 OpenSSH 在工具 ssh-keygen 加了三个选项,协助你管理 hash 了的 known_hosts。你可以用 \ ssh-keygen -F 计算机名称 \ 找出相关的公钥,使用如下命令找出 slave 所对应的公钥
[cpp] view plain copy
ssh-keygen -F slave
执行命令以后得到如下内容:
[cpp] view plain copy
# Host slave found: line 5 type RSA
|1|hMbmluXaSJKOv4bZydZ75Ye3OUc=|rcfbiV7hrXoaDt02BrVb9UxJSqI= ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA0d8quvKVdc0b620eAY46ucB87dK/Q1EqEsPOdUltfEpr7/r9hCG+yJqjM6l3roOzkkc9Fi/iZEx0pvIgDdtD+n5YEQrQu81/mj1cWXmkN9xuXvqv9BZxOTeETRF5g1cL0yr4T91CmvXIMewUzv1fE1pWOzZvMKj8SqMOn7PpTjQhpDoS8SkTuNO81k41DkyrDe3DIRL0yC6aUGTF3YOTAe4DbpF8jMHD3+wDm4JT//ULRNKSwRQPOb57XWHy9GLHm89oOm2e8wrjrz84nCRJ5hgJdsjaPt3qJEEGeb8OAMj2fevyu+e1KDF3KExSE0jGBegEWpJilxaD8AV4+1CHsw==
上述给出了 slave 的公钥,以及在所在的行数。我们去 known_hosts 中找到对应的公钥将其删除
关于“如何解决 ssh 登陆问题”就介绍到这了, 更多相关内容可以搜索丸趣 TV 以前的文章,希望能够帮助大家答疑解惑,请多多支持丸趣 TV 网站!