listing multiple hostnames on an ssh_config Host line

I wanted to use ssh authentication agent forwarding on a few hosts at work because I only keep my private keys at work on my workstation. You enable this on a case by case agent with the ‘-A’ option, but I don’t like remember such things, so you can add ‘ForwardAgent yes’ to your ~/.ssh/config file. However, it seemed unneeded to enable this for all hosts, as it’s got a slight security issue or two. You can limit the commands to a certain host by preceding the command with a ‘Host server_hostname’ line, but ‘server_hostname’ must match whatever you write on the command line. You can use wildcards to match a domain like ‘*.example.org’ but I really only use hostnames not fqdns when I use ssh, so I wanted to list multiple hostnames. You can do this like so:

Host *
ForwardX11 yes
ForwardX11Trusted no

Host ops ops.example.org secretbox otherbox
ForwardAgent yes

1 thought on “listing multiple hostnames on an ssh_config Host line

  1. Josh

    Nice tip, I was looking for exactly this today, thanks! One point to note, when configuring contrasting options for different hosts, the specific Hosts directive must come before the “generic” one…

    Hosts ops.example.org
    Compression no

    Hosts *
    Compression yes

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.