Can one use the output of a command/script in an ssh_config 'match'?
Chris Green
cl at isbd.net
Mon Nov 9 00:08:06 AEDT 2026
On Sun, Nov 08, 2026 at 02:44:57PM +0200, Lars Noodén via openssh-unix-dev wrote:
> On 11/8/26 14:15, Chris Green wrote:
> > I have a script which generates a list of hosts, it's used in various
> > places on my LAN systems for configuration management and such.
> >
> > It would be very handy if I could use its output in a match in my
> > ~/.ssh/config file. I.e. I would like to be able to do something like:-
> >
> > Match host $(listofhosts) exec <bla bla bla>
> > <set something>
> > <set something else>
> >
> > where '$(listofhosts)' inserts the output of listofhosts in the Match line.
> >
> > Is there any way of doing something like this? I've looked through the
> > ssh_config man page quite carefully and I don't see anything, but
> > (hopefully) maybe I'm missing something.
> One way is for the action needed to check the list be inside a script
> called by an Exec under the Match line. You can even have multiple Exec
> calls per Match,
>
> Match exec "listofhostslookup.pl %h" exec "bla bla bla"
> <set something>
> <set something else>
>
> See ssh_config(5) for the full list of tokens available, if you need
> others.
>
Thanks for this and the other reply, I hadn't thought of using more than
one exec. After staring at it for a little while it has suddenly dawned
on me that "listofhostslookup.pl %h" will return true or false depending
on whether %h is in what is returned by my original "listofhosts" command.
My 80 year old brain is getting a little slower on the uptake than it used
to be! :-)
Thanks again all.
--
Chris Green
More information about the openssh-unix-dev
mailing list