A TRAMP file name can omit the user name part since
TRAMP substitutes the currently logged-in user name. However
this substitution can be overridden with tramp-default-user
.
For example:
(customize-set-variable 'tramp-default-user "root")
Instead of a single default user, tramp-default-user-alist
allows multiple default user values based on access method or host
name combinations. The alist can hold multiple values. For example, to
use the ‘john’ as the default user for the domain
‘somewhere.else’ only:
(add-to-list 'tramp-default-user-alist '("ssh" ".*\\.somewhere\\.else\\'" "john"))
A Caution: TRAMP will override any default user specified in
the configuration files outside Emacs, such as ~/.ssh/config.
To stop TRAMP from applying the default value, set the
corresponding alist entry to nil
:
(add-to-list 'tramp-default-user-alist '("ssh" "\\`here\\.somewhere\\.else\\'" nil))
The last entry in tramp-default-user-alist
should be reserved
for catch-all or most often used login.
(add-to-list 'tramp-default-user-alist '(nil nil "jonas") t)