Can one use the output of a command/script in an ssh_config 'match'?
Lars Noodén
lars.nooden at gmx.com
Sun Nov 8 23:44:57 AEDT 2026
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.
/Lars
More information about the openssh-unix-dev
mailing list