SSH配置替换

时间:2015-10-30 20:23:53

标签: ssh

是否可以在ssh_config中编辑替换?我知道我可以匹配通配符,例如:

Host project*
  HostName %h.domain.com
  User project_user

因此使用:

ssh project000
rsync data project123:~

但是更复杂的规则可能吗?如何匹配主机名别名(没有明确生成所有可能的组合)?

p    -> project000.domain.com
p1   -> project001.domain.com
p123 -> project123.domain.com

以防万一:我同时使用bash和zsh

2 个答案:

答案 0 :(得分:1)

No. It is not possible. OpenSSH doesn't have any instrument to provide these substitutions.

You would have to pre-generate the pairs in advance to your ssh_config for ssh to use them.

Or you would have to create bash function that would do the substitution for you, like this:

function ssh() {
  ssh "project${1:1}.domain.com"
}

It would need some more care to support all your cases with ssh, scp, rsync and passing other parameters also.

答案 1 :(得分:0)

这就是我的管理方式:

我的git log

~/.ssh/config

还有Host project* ProxyCommand ~/bin/ssh_proxy %h

~/bin/ssh_proxy