如何指定 OpenSSH 的 SSH 客户端(OpenSSH_7.5p1、OpenSSL 1.0.2k 26 Jan 2017;Git for Windows v2.11.1)向 SSH 兼容守护程序(例如 Apache Mina SSHD (Gerrit))提供公钥/私钥对的顺序代码审查服务)。我的目的是在回退到 RSA 之前尝试使用 Ed25519 公钥/私钥对进行身份验证。
假设用户主目录下有以下标准 Ed25519 和 RSA 公钥/私钥对:
~/.ssh/id_ed25519{,.pub}
~/.ssh/id_rsa{,.pub}
以及用户 SSH 配置文件 (~/.ssh/config) 中的以下主机部分:
Host foobar foobar.example.com
Hostname foobar.example.com
IdentityFile ~/.ssh/id_ed25519
Host *
IdentityFile ~/.ssh/id_ed25519
IdentityFile ~/.ssh/id_rsa
在调试模式下测试 SSH 连接时:
$ ssh -Tv bob@foobar
debug1: Reading configuration data ~/.ssh/config
debug1: ~/.ssh/config line 49: Applying options for foobar
debug1: ~/.ssh/config line 63: Applying options for *
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: ~/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Offering ED25519 public key: ~/.ssh/id_ed25519
debug1: Server accepts key: pkalg ssh-ed25519 blen 51
debug1: Authentication succeeded (publickey).
我可以看到 OpenSSH 的 SSH 客户端首先提供 RSA 公钥/私钥对。但为什么不先Ed25519呢?
答案1
添加IdentitiesOnly
选项。如果没有此选项,SSH 将首先尝试可用的默认 ssh 密钥:id_rsa
, id_dsa
, id_ecdsa
。要更改此行为,请将您的配置替换为以下配置:
Host foobar foobar.example.com
Hostname foobar.example.com
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
Host *
IdentityFile ~/.ssh/id_ed25519
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes