Next: , Previous: Remote programs, Up: Configuration

5.16 Remote shell setup hints

Tramp checks for the availability of standard programs in the usual locations. Common tactics include successively trying test -e, /usr/bin/test -e, and /bin/test -e. ls -d is another approach. But these approaches do not help with these new login patterns.

When Tramp encounters two-factor logins or additional challenge questions, such as entering birth date or security code or passphrase, Tramp needs a few more configuration steps to accommodate them.

The difference between a password prompt and a passphrase prompt is that the password for completing the login while the passphrase is for authorizing access to local authentication information, such as the ssh key.

There is no one configuration to accommodate all the variations in login security, especially not the exotic ones. However, Tramp provides a few tweaks to address the most common ones.

tramp-shell-prompt-pattern is for remote login shell prompt, which may not be the same as the local login shell prompt, shell-prompt-pattern. Since most hosts use identical prompts, Tramp sets a similar default value for both prompts.
Tramp uses tramp-password-prompt-regexp to distinguish between prompts for passwords and prompts for passphrases. By default, tramp-password-prompt-regexp handles the detection in English language environments. See a localization example below:
              '("passphrase" "Passphrase"
                ;; English
                "password" "Password"
                ;; Deutsch
                "passwort" "Passwort"
                ;; Fran├žais
                "mot de passe" "Mot de passe")
             ".*:\0? *"))

Similar localization may be necessary for handling wrong password prompts, for which Tramp uses tramp-wrong-passwd-regexp.

Tramp uses the user option tramp-terminal-type to set the remote environment variable TERM for the shells it runs. Per default, it is ‘"dumb"’, but this could be changed. A dumb terminal is best suited to run the background sessions of Tramp. However, running interactive remote shells might require a different setting. This could be achieved by tweaking the TERM environment variable in process-environment.
          (let ((process-environment
                 (cons "TERM=xterm-256color" process-environment)))

Determining a Tramp session
Sometimes, it is needed to identify whether a shell runs under Tramp control. The setting of environment variable TERM will help:
          if test "$TERM" = "dumb"; then

Another possibility is to check the environment variable INSIDE_EMACS. Like for all subprocesses of Emacs, this is set to the version of the parent Emacs process, See Interactive Shell. Tramp adds its own package version to this string, which could be used for further tests in an inferior shell. The string of that environment variable looks always like

          echo $INSIDE_EMACS
          ⇒ 26.2,tramp:2.3.4

tset and other questions
To suppress inappropriate prompts for terminal type, Tramp sets the TERM environment variable before the remote login process begins via the user option tramp-terminal-type (see above). This will silence common tset related prompts.

Tramp's strategy for handling such prompts (commonly triggered from login scripts on remote hosts) is to set the environment variables so that no prompts interrupt the shell initialization process.

An alternative approach is to configure Tramp with strings that can identify such questions using tramp-actions-before-shell. Example:

          (defconst my-tramp-prompt-regexp
            (concat (regexp-opt '("Enter the birth date of your mother:") t)
            "Regular expression matching my login prompt question.")
          (defun my-tramp-action (proc vec)
            "Enter \"19000101\" in order to give a correct answer."
              (with-current-buffer (tramp-get-connection-buffer vec)
                (tramp-message vec 6 "\n%s" (buffer-string))
                (tramp-send-string vec "19000101"))))
          (add-to-list 'tramp-actions-before-shell
                       '(my-tramp-prompt-regexp my-tramp-action))

Conflicting names for users and variables in .profile
When a user name is the same as a variable name in a local file, such as .profile, then Tramp may send incorrect values for environment variables. To avoid incorrect values, change the local variable name to something different from the user name. For example, if the user name is FRUMPLE, then change the variable name to FRUMPLE_DIR.
Non-Bourne commands in .profile
When the remote host's .profile is also used for shells other than Bourne shell, then some incompatible syntaxes for commands in .profile may trigger errors in Bourne shell on the host and may not complete client's Tramp connections.

One example of a Bourne shell incompatible syntax in .profile: using export FOO=bar instead of FOO=bar; export FOO. After remote login, Tramp will trigger an error during its execution of /bin/sh on the remote host because Bourne shell does not recognize the export command as entered in .profile.

Likewise, (~) character in paths will cause errors because Bourne shell does not do (~) character expansions.

One approach to avoiding these incompatibilities is to make all commands in ~/.shrc and ~/.profile Bourne shell compatible so Tramp can complete connections to that remote. To accommodate using non-Bourne shells on that remote, use other shell-specific config files. For example, bash can use ~/.bash_profile and ignore .profile.

Interactive shell prompt
Tramp redefines the remote shell prompt internally for robust parsing. This redefinition affects the looks of a prompt in an interactive remote shell through commands, such as M-x shell <RET>. Such prompts, however, can be reset to something more readable and recognizable using these Tramp variables.

Tramp sets the INSIDE_EMACS variable in the startup script file ~/.emacs_SHELLNAME.

SHELLNAME is bash or equivalent shell names. Change it by setting the environment variable ESHELL in the .emacs as follows:

          (setenv "ESHELL" "bash")

Then re-set the prompt string in ~/.emacs_SHELLNAME as follows:

          # Reset the prompt for remote Tramp shells.
          if [ "${INSIDE_EMACS/*tramp*/tramp}" == "tramp" ] ; then
             PS1="[\u@\h \w]$ "

busybox / nc
Tramp's nc method uses the nc command to install and execute a listener as follows (see tramp-methods):
          $ nc -l -p 42

The above command-line syntax has changed with busybox versions. If nc refuses the ‘-p’ parameter, then overwrite as follows:

           `(,(regexp-quote "")
             "remote-copy-args" (("-l") ("%r"))))

where ‘’ is the remote host IP address (see Predefined connection information).