我的目标是在配置中为主机子集添加一些通用属性。以下两个示例非常接近,只是将主机部分替换为匹配部分和目标主机别名。如果我匹配昵称,此处的第一个示例可以按预期工作。但是,我的目标是将特殊参数应用于特定子网上的每个主机。使用通配符对主机别名进行通配符实际上是不可能的,因为名称不统一,并且有些有多个别名。
Host *
ServerAliveInterval 240
AddressFamily inet
ForwardAgent yes
ForwardX11 yes
ForwardX11Trusted yes
Host server*
IdentityFile ~/.ssh/default_id_rsa
User remoteMe
RequestTTY force
RemoteCommand bash
ProxyJump myproxy
Host myproxy
Hostname 10.1.2.3
User meOnProxy
IdentityFile ~/.ssh/meOnProxy_id_rsa
Host server01
Hostname 192.168.1.11
Host server02
Hostname 192.168.1.12
Host otherserver
Hostname 10.1.15.155
User meOnOtherserver
IdentityFile ~/.ssh/other_id_rsa
但是,我想输入主机名,而不是主机,但下面的方法不起作用,匹配被忽略,并且它会挂起尝试直接查找主机(忽略 JumpProxy 和其他参数)。请帮我解决匹配语法问题。
Host *
ServerAliveInterval 240
AddressFamily inet
ForwardAgent yes
ForwardX11 yes
ForwardX11Trusted yes
Match host 192.168.1.*
IdentityFile ~/.ssh/default_id_rsa
User remoteMe
RequestTTY force
RemoteCommand bash
ProxyJump myproxy
Host myproxy
Hostname 10.1.2.3
User meOnProxy
IdentityFile ~/.ssh/meOnProxy_id_rsa
Host firstserver proc11
Hostname 192.168.1.11
Host servertwo proc12
Hostname 192.168.1.12
Host otherserver
Hostname 10.1.15.155
User meOnOtherserver
IdentityFile ~/.ssh/default_id_rsa
答案1
代替:
# Wrong:
Match host 192.168.1.*
你应该使用:
Match host="192.168.1.*"
使用逗号作为多个主机的分隔符,并使用!
否定:
Match host="!192.168.1.11,192.168.1.*,192.168.2.*"