0

In ssh config you can easily edit a hostname by appending or prepending it with something. For example, when you want to connect to server with ssh test5, but actually the server name is test5.mail, you can specify the server as like this:

Match exec "echo %h | grep -q '^test[0-9]$'"
    HostName %h.mail

The same approach could be applied if you need to prepend hostname.

But what if I want to edit the middle of the hostname? For example, I want to connect as ssh server1.storage, but the actual address I want to connect to is server1.int.storage.

In other words, I want to insert substring in the middle of %h.

2 Answers 2

0

The following worked for me:

Match exec "echo %h | grep -q '^server[0-9]*.storage$'"
    ProxyCommand ssh $(echo %h | sed 's/storage/int.storage/') nc $(echo %h | sed 's/storage/int.storage/') %p

I have found example of proxy command in this question. But I do not completely understand why you need that part with nc and %p. There you specify the edit command twice. I would like to just specify it once, like this:

ProxyCommand ssh $(echo %h | sed 's/storage/int.storage/')

but it is not working.

From the same question linked above, I see that you can also specify the handler script. But it seems the command again should be specified with twice ediding. So I would rather prefer to keep everything in one place - in the ssh config itself.

Would appreciate explanation and other variants of solutions, if any.

0

you can just the nc bit in proxycommand without repeating ssh

Match exec "echo %h | grep -q '^server[0-9]*.storage$'"
    ProxyCommand nc $(echo %h | sed 's/storage/int.storage/') %p

in my case i used it for non dns resolvable aws ec2 names

Match exec "echo %n | grep -qE '^ip-.*\.compute\.internal$'"
ProxyCommand nc $(echo %n | cut -d. -f1 | cut -d- -f2- | tr - .) %p

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .