编辑:--我见过这种方法起作用的情况,也见过这种情况不起作用的情况--我不确定什么时候/为什么会这样。
假设我有一个足够复杂的条目,其中我指定了多个参数以到达thathost
Host thathost
ControlMaster auto
ServerAliveInterval 8
ConnectTimeout 8
Hostname 192.168.5.1
User mememe
ProxyJump thejumpbox我希望在创建额外的条目时重用这个定义,这些条目通过添加或重写一些信任来提供不同的功能。具体地指定一个备用端口(不,我不希望它出现在命令行上)。
理想情况下,我可以做这样的事情
Host theirhost
Hostname thathost
User themthem或
Host my-remote-serialport
Hostname thathost
RequestTTY yes
RemoteCommand some-script-that-launches-kermit-on-a-specific-dev-tty或
Host my-remote-serialport
Hostname thathost
Port 3004我严格地希望用另一个现有主机来指定一个主机,我不想修改我的Host条目来匹配一些模式“技巧”。
显然,我可以使用ProxyCommand ssh -q nc thathost...或ProxyJump thathost +Hostname localhost,然后是所有其他重写(好吧,端口覆盖会将其传递给nc),但这既丑陋又浪费(额外的会话)--请不要回答这个问题。
对我来说,这是ssh-config缺少的特性,但也许我看得不够努力。
发布于 2021-12-30 16:49:29
它不能按您要求的方式使用,比如重用一个hostname定义,但是所提供的ssh解决方案可以解决更多的问题。
主机规则可以跨越多个主机。
Host thathost theirhost my-remote-serialport
ControlMaster auto
ServerAliveInterval 8
ConnectTimeout 8
Hostname 192.168.5.1
User mememe
ProxyJump thejumpbox但很明显,这并不能解决修改某些属性的问题。
诀窍是,ssh配置对属性使用第一个wins策略。
在您的示例中,只需在主配置之前添加修改即可。
Host theirhost
Hostname thathost
User themthem
Host my-remote-serialport
Hostname thathost
Port 3004
Host thathost theirhost my-remote-serialport
ControlMaster auto
ServerAliveInterval 8
ConnectTimeout 8
Hostname 192.168.5.1
User mememe
ProxyJump thejumpboxtheirhost是在两个地方定义的,属性Hostname和User取自第一个定义,所有其他属性都来自第二个定义。
host部件还接受通配符,例如具有多个反向ssh端点的jumpbox:
HOST my_1
port 2001
HOST my_2
port 2002
HOST my_3
port 2003
HOST my_*
user pi
hostname localhost
ProxyJump thejumpbox发布于 2021-12-30 17:00:56
没有方法引用不同的块;但是,您可以包含具有全局配置的特定配置文件。例如,创建一个供thathost、theirhost和my-remote-serialport使用的文件。我们就叫它foo-config吧。
ControlMaster auto
ServerAliveInterval 8
ConnectTimeout 8
Hostname 192.168.5.1
User mememe
ProxyJump thejumpbox然后,您可以根据需要使用Include指令读取该命令:
Host theirhost
Include foo-config
User themthem
Host my-remote-serialport
Include foo-config
RequestTTY yes
RemoteCommand some-script-that-launches-kermit-on-a-specific-dev-tty
Host my-remote-serialport
Include foo-config
Port 3004但是,我怀疑这种方法很少是必要的,而且在大多数情况下,given by jeb方法可能是足够的。
https://stackoverflow.com/questions/70533421
复制相似问题