25

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 `.

1 Answer 1

52

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.

5
  • 2
    A couple of follow-up questions:1) Has the behavior changed recently? The guide at the linked website clearly shows Host * in the top.
    – andyn
    Commented Feb 18, 2014 at 12:04
  • 2) The first match wins, but apparently only for those values it explicitly sets. Is this documented somewhere? Man ssh_config does not show anything related in Host or PATTERNS sections.
    – andyn
    Commented Feb 18, 2014 at 12:14
  • 12
    First sentence in the second paragraph in ssh_config(5) says: "For each parameter, the first obtained value will be used." I don't know if that changed recently, but I had "Host *" at the bottom all the time.
    – cran
    Commented Feb 18, 2014 at 13:04
  • I should note that after moving the Host * to the bottom I had to restart ssh-agent for the new placement to take effect. Commented Jun 25, 2020 at 16:18
  • Thank you! I've added a quote of man 5 ssh_config for clarity. I've had my defaults at the top for years, but never needed to override any of those settings. Many examples also follow the incorrect * first style.
    – spazm
    Commented Jul 15, 2020 at 16:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .