Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSH config substitutions

Tags:

ssh

Is it possible to edit substitutions within ssh_config? I know I can match wildcards such as:

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

Used thus:

ssh project000
rsync data project123:~

But are more complex rules possible? How about match to a hostname alias (without explicitly generating every possible combination)?

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

Just in case: I use both bash and zsh

like image 822
user3769065 Avatar asked Oct 19 '22 23:10

user3769065


1 Answers

This is how I'm managing this:

My ~/.ssh/config:

Host project*
    ProxyCommand ~/bin/ssh_proxy %h

And ~/bin/ssh_proxy:

#!/bin/zsh

function make_host {
    HOST_NUM=${1[8,999]}
    echo project${(l(3)(0))HOST_NUM}
}

exec nc `make_host $1` 22
like image 78
Konstantin Nikitin Avatar answered Oct 22 '22 21:10

Konstantin Nikitin