Linux – OpenSSH ~/.ssh/config host-specific overrides not working

linuxopensshsshUbuntu

I've tried setting up my ~/.ssh/config file with the help of this guide. However, the host-specific User override has no effect and ssh tries to connect using the global username instead of the host-specific one. My ssh config is set up like this:

$ cat ~/.ssh/config
User my_global_username

Host dev1
    HostName 10.40.10.41
    User my_username_on_dev_machines

I've also tried putting the global user name below a Host * entry to no avail. The OpenSSH version and build I'm running is OpenSSH_6.2p2 Ubuntu-6ubuntu0.1, OpenSSL 1.0.1e 11 Feb 2013
`.

Best Answer

There is no "global" value in .ssh/config. If you want to have a default value you have to put it in a Host * section:

Host dev1
    HostName 10.40.10.41
    User my_username_on_dev_machines

Host *
    User my_global_username

Note the ordering: The first match wins!

from man 5 ssh_config:

Since the first obtained value for each parameter is used, more host-specific declarations should be given near the beginning of the file, and general defaults at the end.