Next: , Previous: Default Method, Up: Configuration

4.7 Selecting a default user

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:

     (setq 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"))

See the documentation for the variable tramp-default-user-alist for more details.

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)