genx1mx6
genx1mx6

Reputation: 453

Is there a way to use variables or code in ssh config?

Imagine you have X sites and each site has a naming schema they use for proxy access. I'd like to create an ssh config file that would satisfy all X sites but not duplicate my ssh config.

For example, if I'm at an ssh host at site A I want the ssh config file to derive that it's on a site A host by taking the first 3 characters of the host name. this is a dummy config file, but only site A hosts can access site A hosts. only site B for site B... etc. instead of having 4 entries I'd like to just use 2.

Host siteA*-worker
    ProxyCommand ssh -qxT -At siteA_security nc %h %p

Host siteA*-worker2
    ProxyCommand ssh -qxT -At siteA_security nc %h %p

should be something like

Host $(hostname | cut -c1-2)*-worker
    ProxyCommand ssh -qxT -At $(hostname | cut -c1-2)_security nc %h %p

Host $(hostname | cut -c1-2)*-worker2
    ProxyCommand ssh -qxT -At $(hostname | cut -c1-2)_security nc %h %p

Upvotes: 0

Views: 47

Answers (0)

Related Questions