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.
The following worked for me:
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:
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.
you can just the nc bit in proxycommand without repeating ssh
in my case i used it for non dns resolvable aws ec2 names