HowTo: Set default username for ssh remote hosts

less than 1 minute read

If your local username is different than your remote host it may be frustrating to type that username at each connection. Luckily, ssh comes with a config file that we can adjust.

Create the config file under~/.ssh directory.

touch ~/.ssh/config

Edit the file as such:

        User foo
    Host *.myAnotherDomain
        User bar
    Host *
        User foobar

You can use asterisk to match all hosts or subdomains. The configuration above will use

  1. User foo for

  2. User bar for all subdomains under

  3. User foobar for any host that doesn’t match with above.

Note for Windows Users

If you are using PuTTY, maybe it’s time for you to switch to GNU tools. MinGW or Cygwin is a great start for that.

However, that GNU tools come with their own home directory. So, if you are using MinGW Shell, then your home directory is may not be your Windows home directory. Type printenv | grep HOME and it will show your POSIX home directory. So, if you are using MinGW shell for ssh, you should create that config under that directory. Otherwise, your good old Windows Home %USERPROFILE%

Enjoy hacking 🙂