这个问题可能属于 Ask Different 社区,但我会在这里问,因为这更像是一个 unix 问题。
我使用的是运行 OSX 10.12.4 的 MBP。在我的终端窗口中,当我通过 ssh 连接到 localhost 时,它使用的是“ECDSA 密钥”。我之前已经设置了一个 RSA 密钥,所以我不知道它为什么尝试使用 ECDSA 密钥。我甚至不知道 ECDSA 是什么,而且我也没有故意用这个算法设置密钥。如果我尝试连接到另一台服务器,它会毫无问题地使用我的 RSA。
这是我尝试 ssh 到 localhost 时的输出:
$ ssh localhost
The authenticity of host 'localhost (::1)' can't be established.
ECDSA key fingerprint is SHA256:1234567.
Are you sure you want to continue connecting (yes/no)? no
Host key verification failed.
这是我尝试 ssh 到远程服务器时的输出:
ssh hostname.domainname.com
The authenticity of host 'hostname.domainname.com (10.10.10.10)' can't be established.
RSA key fingerprint is SHA256:abcdefg.
(yes, the fingerprint different from ECDSA key above)
Are you sure you want to continue connecting (yes/no)?
我之前设置了一个本地单节点 Hadoop 集群,但发生了一些事情,导致我现在无法启动集群,因为我无法 ssh 到 localhost。我删除了 known_hosts 文件中所有提到 127.0.0.1 或 localhost 的条目,但仍然有问题。在我的 .ssh/config 文件中,我没有提到 ECDSA。
如何让我的笔记本电脑在 ssh 进入本地主机时停止使用 ECDSA?我为什么最后还是使用 ECDSA?任何帮助我都感激不尽。
编辑 #2:当我运行 时ssh -v localhost
,我看到一些有趣的消息。希望有人能帮助我解读这是什么意思,因为这对我来说毫无意义。我的id_rsa
文件存在,但它说它不存在:
$ ssh -v localhost
OpenSSH_7.4p1, LibreSSL 2.5.0
debug1: Reading configuration data /Users/first.last/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 53: Applying options for *
debug1: Connecting to localhost [::1] port 22.
debug1: Connection established.
debug1: identity file /Users/first.last/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/first.last/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/first.last/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/first.last/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/first.last/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/first.last/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/first.last/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/first.last/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: match: OpenSSH_7.4 pat OpenSSH* compat 0x04000000
debug1: Authenticating to localhost:22 as 'first.last'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:Zg4yEz5WCZVbQEutpAM5zRw+Tk+2gUGFtSYOSTsVfTU
debug1: Host 'localhost' is known and matches the ECDSA host key.
debug1: Found key in /Users/first.last/.ssh/known_hosts:75
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/first.last/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
Authentication failed.
$
我的 .ssh 目录的内容如下,所以当操作系统说 id_rsa 不存在时我不知道它是怎么回事,除非权限以某种方式混淆了我:
authorized_keys* id_rsa config*
id_rsa.pub* known_hosts*
答案1
我认为您混淆了主机密钥和用户密钥。当您通过 SSH 连接到主机时,主机会使用其主机密钥向您验证身份,然后您使用用户密钥向主机验证身份。
Mac 一直都是自己生成主机密钥。macOS 的最新版本已从 RSA 主机密钥升级为 ECDSA 主机密钥,因为椭圆曲线加密被认为比 RSA 更安全。RSA 的安全性取决于这样一个事实:没有人找到一种简单的方法来分解大素数的乘积。不幸的是,没有人已证实我相信椭圆曲线密码学是可证明的难密码学。
从 known_hosts 中删除对 localhost 和 127.0.0.1 的引用时,也请删除 的所有条目::1
,这是 127.0.0.1 的 IPv6 等效项。
您无需将 Mac 的 SSH 主机密钥从 ECDSA 降级为 RSA 即可使 SSH 进入 localhost 正常工作。只需在 SSH 进入 localhost 时输入一次“yes”,其 ECDSA 主机密钥就会存储在您的 known_hosts 文件中。