【发布时间】:2021-06-24 13:49:49
【问题描述】:
在OpenSSH 8.2中更改sshd端口后,发现ssh指纹发生了变化。这让我很惊讶,因为我认为它只是依赖于公钥。
指纹取决于什么?港口是它的一部分吗?
仔细检查后,密钥似乎从 ssh-rsa 更改为 ecdsa-sha2-nistp256。看起来服务器有多个密钥文件。什么决定了使用哪个密钥以及可能导致更改的原因是什么?
【问题讨论】:
在OpenSSH 8.2中更改sshd端口后,发现ssh指纹发生了变化。这让我很惊讶,因为我认为它只是依赖于公钥。
指纹取决于什么?港口是它的一部分吗?
仔细检查后,密钥似乎从 ssh-rsa 更改为 ecdsa-sha2-nistp256。看起来服务器有多个密钥文件。什么决定了使用哪个密钥以及可能导致更改的原因是什么?
【问题讨论】:
我没有找到官方文档,但遇到了类似的困惑,所以只是尝试了一下。
指纹(.ssh/known_hosts)中的主机名经过哈希处理,但您可以使用ssh-keygen -H -F 'remote' 进行检查(您会看到Host remote found...)
如果你使用默认端口(22),当你第一次运行ssh remote时,指纹似乎只包含主机名。
您可以使用ssh-keygen -H -F 'remote' 进行检查(您会看到Host remote found...)
现在,如果您更改 remote 上的 sshd 端口(例如,更改为 1234),ssh 似乎仍然对此感到满意,因为它会尝试匹配没有端口的主机名。
您可以通过-v 标志看到这一点:
$ ssh -v remote -p 1234
debug1: Authenticating to remote:1234 as 'user'
...
debug1: checking without port identifier
debug1: Host 'remote' is known and matches the ECDSA host key.
debug1: Found key in /home/user/.ssh/known_hosts:11
但是——如果你第一次 ssh 到 remote 是使用自定义端口 (ssh remote -p 1234),那么它似乎会记住带有端口的主机名:
ssh-keygen -H -F 'remote' -- 不会产生任何结果ssh-keygen -H -F '[remote]:1234' -- 匹配结果ssh 输出也略有变化,现在正在检查主机和端口:
$ ssh -v remote -p 1234
...
debug1: Host '[remote]:1234' is known and matches the ECDSA host key.
debug1: Found key in /home/user/.ssh/known_hosts:12
...
现在如果你把远程 sshd 端口改成别的东西,说回22,然后运行ssh remote,ssh 将无法验证主机,因为它只知道[remote]:1234,不知道@ 987654339@。
(我猜理论上它仍然可以对照.ssh/known_hosts 检查所有 65535 端口并给出更友好的错误消息)。
关于关键选择:相同的-v 标志在这里可能会有所帮助:
...
debug1: Will attempt key: /home/user/.ssh/id_rsa RSA <redacted> agent
debug1: Will attempt key: /home/user/.ssh/id_dsa
debug1: Will attempt key: /home/user/.ssh/id_ecdsa
debug1: Will attempt key: /home/user/.ssh/id_ecdsa_sk
debug1: Will attempt key: /home/user/.ssh/id_ed25519
debug1: Will attempt key: /home/user/.ssh/id_ed25519_sk
debug1: Will attempt key: /home/user/.ssh/id_xmss
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<redacted>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering public key: /home/user/.ssh/id_rsa RSA <redacted> agent
debug1: Server accepts key: /home/user/.ssh/id_rsa RSA <redacted> agent
...
【讨论】: