Default SSH user on Linux

A better solution than putting an alias in your bashrc, would be to use a ssh config file

cat ~/.ssh/config

HOST *  
     USER root

You can also specify certain subdomains use certain users. Useful if your laptop travels between networks.

HOST 192.168.*.*
     USER homeuser

HOST 10.2.*.*
     USER workuser

You could even configure by domains, and use different ssh keys for different domains.

HOST *.microsoft.com
     USER bill
     IdentityFile ~/.ssh/microsoft/id_rsa

HOST *.apple.com
     USER steve
     IdentityFile ~/.ssh/apple/id_rsa

You can also add sections that apply to multiple hosts, e.g.

HOST rasbpi1 rasbpi2 rasbpi3
    USER pi

Read more about the format by executing man ssh_config or here


How to have a default user, and host-specific users

To be clear, if you want BOTH a default user AND host-specific users, you need to use Host *, and put it at the bottom of the config file:

~/.ssh/config:

#
# Aliases
#

Host dev
    Hostname dev.example.com

Host mac
    Hostname mac.local


#
# Host-specific users
#

Host dev dev.example.com
    User root

Host mac mac.local
    User me


#
# Default user
#

Host *
    User app

References

  • https://therootcompany.com/blog/ssh-defaults-config-and-priorities/