Define multiple (similar) hosts with one ssh config entry

Posted . Visible to the public.

Instead of

Host host1
    HostName host1.namespace.com
    ForwardAgent yes
    Port 1234
    User judith
    IdentityFile /Path/to/file
    
Host host2
    HostName host2.namespace.com
    ForwardAgent yes
    Port 1234
    User judith
    IdentityFile /Path/to/file
    
Host host3
    HostName host3.namespace.com
    ForwardAgent yes
    Port 1234
    User judith
    IdentityFile /Path/to/file

You can just add one entry and work with a placeholder:

Host host1 host2 host3
    HostName %h.namespace.com
    ForwardAgent yes
    Port 1234
    User judith
    IdentityFile /Path/to/file

There are even more placeholders available, see man ssh_config!

Judith Roth
Last edit
Judith Roth
Posted by Judith Roth to Judith's Dev Notes (2022-09-19 16:08)