大网数据广告活动
服务器运维问答

Rewrite / Redirect Host With SSH Config File?

· 52CE 我爱测

My company has three separate jump hosts. Something like: jump1.example.com , jump2.example.com , and jump3.example.com All internal servers must be accessed through these jumphosts: local ---> jump1.example.com ---> internal.exa…

问题原文

原帖链接 · stevendesu · CC BY-SA 4.0

My company has three separate jump hosts. Something like: jump1.example.com, jump2.example.com, and jump3.example.com

All internal servers must be accessed through these jumphosts:

local ---> jump1.example.com ---> internal.example.com

We have lots of internal servers, so to simplify I created a config file like so:

.ssh/config:

Host jump1.example.com jump2.example.com jump3.example.com
    ForwardAgent yes
    ProxyCommand none

Host *.example.com
    PubkeyAuthentication yes
    User sbarnett
    IdentityFile ~/.ssh/id_rsa
    IdentitiesOnly yes
    ProxyCommand ssh -q -W %h:%p jump1.example.com

Note that my public key is located on every one of these machines, so this setup works perfectly. I can type ssh internal.example.com and it will properly proxy through jump1.example.com and connect with my private key

Here's what I want to do, though: Instead of typing jump1.example.com or internal.example.com, I'd like to just type ssh jump1 or ssh internal

I know that this can be configured per host like so:

Host internal
    HostName internal.example.com
    PubkeyAuthentication yes
    User sbarnett
    IdentityFile ~/.ssh/id_rsa
    IdentitiesOnly yes
    ProxyCommand ssh -q -W %h:%p jump1.example.com

However if I try the much simpler:

Host internal
    HostName internal.example.com

Then my generic config options (under *.example.com) are not loaded when I try to use ssh internal -- so it doesn't use the proxy and doesn't use the identity file, preventing me from connecting.

Is there a way to say "if the host name is *.example.com (not necessarily the host) then apply these settings"?

Bonus points for a way to redirect * to *.example.com if and only if * does not exist (e.g. - when connecting to [email omitted] I don't want it to redirect to [email omitted])

已采纳解答

原帖链接 · Andrew Domaszek · CC BY-SA 4.0

The option you're looking for is CanonicalizeHostname.

If you add these to the top of your .ssh/config, ssh internal will try to dns resolve your entry speculatively as internal.example.com, and if successful, it will process it matching Host *.example.com. The CanonicalDomains line can have multiple entries that are tried in order.

CanonicalDomains example.com
CanonicalizeHostname yes

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-07-18)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。