由于我想保护我的 ssh 连接,我设置了一些全局密码套件选项来限制使用的算法集。但是最近我遇到了一个不支持其中一些算法的服务器。因此,我需要有选择地为客户端(我的系统)配置中的特定主机记录启用已弃用的算法。
我发现选项覆盖没有按我预期的那样工作。让我们为 github 举一个最小的(非)工作示例:
HostKeyAlgorithms ssh-ed25519-cert-v01@openssh.com,ssh-ed25519,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp521,ecdsa-sha2-nistp256
Host github
HostKeyAlgorithms ssh-rsa
Hostname github.com
Port 22
User git
PubkeyAuthentication yes
IdentityFile ~/.ssh/some-filename-here
Run Code Online (Sandbox Code Playgroud)
有了这个,我收到以下错误(HostKeyAlgorithms
根本没有被覆盖):
debug1: /home/username/.ssh/config line 14: Applying options for github
<...>
debug2: kex_parse_kexinit: ssh-ed25519-cert-v01@openssh.com,ssh-ed25519,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp521,ecdsa-sha2-nistp256
<...>
Unable to negotiate with 192.30.252.130: no matching host key type found. Their offer: ssh-dss,ssh-rsa
Run Code Online (Sandbox Code Playgroud)
它同样不适用于PubkeyAuthentication no
在主机配置中覆盖的全局选项。
此外,这match
也无济于事:
match host github
HostKeyAlgorithms ssh-rsa
Run Code Online (Sandbox Code Playgroud)
那么,有没有办法选择性地重新定义这些选项?
注意:我在 gentoo 上使用 openssh-7.1_p2-r1。
乍一看,OpenSSH 选项可能表现得有些奇怪。但手册页ssh_config
很好地记录了它:
\n\n\n对于每个参数,将使用第一个获得的值。配置文件包含由 \xe2\x80\x9cHost\xe2\x80\x9d 规范分隔的部分,并且该部分仅适用于与规范中给出的模式之一匹配的主机。匹配的主机名通常是命令行上给出的主机名(有关例外情况,请参阅 CanonicalizeHostname 选项。)
\n
您可以像这样重写您的配置来实现您所需要的:
\n\nHost github\n HostKeyAlgorithms ssh-rsa\n Hostname github.com\n Port 22\n User git\n PubkeyAuthentication yes\n IdentityFile ~/.ssh/some-filename-here\nHost *\n HostKeyAlgorithms ssh-ed25519-cert-v01@openssh.com,ssh-ed25519,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp521,ecdsa-sha2-nistp256\n
Run Code Online (Sandbox Code Playgroud)\n
归档时间: |
|
查看次数: |
3466 次 |
最近记录: |