The actual problem I'm trying to solve is that Tramp does not use the PATH of the remote machine it's SSH-ing to. One workaround is to from the client set PATH depending on which machine Tramp is visiting.

The emacs manual describes how to set this up for a single machine.

Single machine matching

#+begin_src bash :dir /ssh:hype:/
echo $PATH
mmlsfs -h

: hype
: /usr/bin:/bin:/sbin:/usr/sbin:/usr/local/sbin
: bash: line 4: mmlsfs: command not found

#+begin_src elisp
(connection-local-set-profile-variables 'remote-path-with-gpfs
 '((tramp-remote-path . ("/usr/lpp/mmfs/bin/" tramp-default-remote-path))))

 '(:application tramp :machine "hype") 'remote-path-with-gpfs)

:  ((:application tramp :machine "hype")
:   remote-path-with-gpfs)
:  ((:application tramp)
:   tramp-connection-local-default-profile))

#+begin_src bash :dir /ssh:hype:/
echo $PATH
mmlsfs -h

   mmlsfs {Device | all | all_local | all_remote} [-A] [-B] [-d] [-D]

And for a single machine this works well. But I would like to set the same PATH for a couple of hundred machines. That or have Tramp inherit PATH from the machine it lands on.

I have tried to grok the code for the subst connection-local-get-profiles in files-x.el but have yet to understand if it does anything but literal equality checks.

Hypothethical example

If, for example, regexes were accepted and matched the following criteria would match both machines named n1 and n500.

 '(:application tramp :machine "n[:digit:]+") 'remote-path-with-gpfs)

This would result in the following code block evaluating like it did on hype.

#+begin_src bash :dir /ssh:hype|su:root@hype|ssh:n1:/
echo $PATH

: n1
: /usr/bin:/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin
: bash: line 4: mmlsfs: command not found


Is it possible to match multiple machines with a criteria. Or is it possible to have Tramp inherit PATH from the machine it lands on.

I could iterate over a generated list of all the machines I want to match and add one rule per machine. But that would mean Emacs having to evaluate all hundred criteria per connection it ever sets up, which seems less than ideal.

1 Answer 1


connection-local-criteria-alist uses strings for the properties, not regexps. But you can simply leave the :machine property out, like

 '(:application tramp) 'remote-path-with-gpfs)

You can also use another property for identifying the hosts you are already in, like :user or :protocol.

  • Is there any harm in having a path in Tramps PATH that does not exist?
    – Rovanion
    Commented Sep 14, 2023 at 14:53
  • There shouldn't be a problem. Commented Sep 15, 2023 at 7:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.