nhe*_*hed 1 ssh openssh ssh-config
编辑:我见过这种方法有效的情况和无效的情况,我不确定我何时/为何这样做。
假设我有一个足够复杂的条目,我在其中指定了多个参数thathost:
Host thathost
ControlMaster auto
ServerAliveInterval 8
ConnectTimeout 8
Hostname 192.168.5.1
User mememe
ProxyJump thejumpbox
Run Code Online (Sandbox Code Playgroud)
我想在创建其他条目时重新使用此定义,通过添加或覆盖某些配置来提供不同的功能。特别指定备用端口(不,我不想在命令行上使用它)。
理想情况下我能够做类似的事情
Host theirhost
Hostname thathost
User themthem
Run Code Online (Sandbox Code Playgroud)
或者
Host my-remote-serialport
Hostname thathost
RequestTTY yes
RemoteCommand some-script-that-launches-kermit-on-a-specific-dev-tty
Run Code Online (Sandbox Code Playgroud)
或者
Host my-remote-serialport
Hostname thathost
Port 3004
Run Code Online (Sandbox Code Playgroud)
我严格要求根据另一台现有主机来指定一台主机,我不想修改我的Host条目以匹配某些模式“技巧”。
显然,我可以利用ProxyCommand ssh -q nc thathost...or ProxyJump thathost+Hostname localhost后跟所有其他覆盖(对于端口覆盖来说,会将其传递给nc),但这既丑陋又浪费(额外的会话) - 请不要回答这个问题。
对我来说,这是 的缺失功能ssh-config,但也许我看起来不够仔细。
它不能按照您要求的方式使用,例如重用定义hostname,但 ssh 提供的解决方案可以解决更多问题。
主机规则可以跨越多个主机。
Host thathost theirhost my-remote-serialport
ControlMaster auto
ServerAliveInterval 8
ConnectTimeout 8
Hostname 192.168.5.1
User mememe
ProxyJump thejumpbox
Run Code Online (Sandbox Code Playgroud)
但显然这并不能解决你修改某些属性的问题。
诀窍是,ssh 配置对属性使用第一个获胜策略。
在您的情况下,您只需在主配置前面添加修改
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 thejumpbox
Run Code Online (Sandbox Code Playgroud)
theirhost在两个地方定义,属性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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1038 次 |
| 最近记录: |