Tramp using ssh does not source .bash_profile / .profile
Asked Answered
H

2

10

I'm using Aquamacs (graphical emacs for OSX using emacs 24 and tramp version 2.2.3) to edit some files on a remote server. Tramp is set up to use ssh and works fine in terms of editing files.

It fails when it comes to compiling because the compiler is not in the path. It seems like tramp does not source any of the profile files like .profile or .bash_profile. /bin/sh is a link to /bin/bash so bash should be the shell used by tramp. A shell started within emacs on the remote server won't source anything, too. A ssh connection from a regular terminal emulator (tried Terminal and X11 on OS X) works as expected (everything sourced correctly).

Any ideas?

Haar answered 5/5, 2012 at 15:13 Comment(1)
M
5

/bin/sh is a link to /bin/bash so bash should be the shell used by tramp.

Its not the same. When invoked as "sh", it will behave like sh and not bash, hence the bash specific rc/profile files (e.g. ~/.bash_profile, ~/.bashrc) won't be sourced. However ~/.profile will be read. Your problem might be you are using bash syntax to setup stuff in your ~/.profile.

This will not work:

export PATH=/some/path:$PATH

But this will:

PATH=/some/path:$PATH
export PATH
Murdocca answered 5/5, 2012 at 18:5 Comment(2)
In my case .profile is totally ignored. Sourcing it by hand when invoked /bin/sh does in fact result in a correct path but on its own tramp seems not to source ~/.profile.Haar
I'm not sure whether putting export PATH on a separate line in ~/.profile or ~/.bash_profile would make tramp understand it, but I tried to make EDITOR be set by tramp in a similar way, and it didn't work neither in ~/.profile nor ~/.bash_profile, so I ended up setting it once again through tramp-remote-process-environment, as I told in emacs.stackexchange.com/a/7685/5165 , which is not totally convenient because different remote hosts might need different values.Ochre
Y
4

I had this problem, and could see from my shell history that tramp was executing /bin/sh as a non-login shell, meaning that ~/.profile wouldn't be executed.

This sounds like what the emacs manual is saying here:

Another way to find the remote path is to use the path assigned to the remote user by the remote host. Tramp does not normally retain this remote path after login. However, tramp-own-remote-path preserves the path value, which can be used to update tramp-remote-path.

      (add-to-list 'tramp-remote-path 'tramp-own-remote-path)

Note that this works only if your remote /bin/sh shell supports the login argument ‘-l’.

Adding 'tramp-own-remote-path to tramp-remote-path as described added the -l flag to the command I saw in my history and sourced ~/.profile, as expected.

(This is described in the accepted answer to the question linked in Ivan's comment, but it doesn't mention that the PATH is respected by sourcing ~/.profile, which means other environment customization can be done in that file.)

Yawata answered 12/4, 2020 at 9:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.