views:

42

answers:

3

Hello,

I have a problem with the PATH variable on Debian Linux when executing commands via SSH. This happens for example when I use GIT or Mercurial and I have them installed in /opt instead of /usr/local. But I can also reproduce this easily like this:

When I login to the server via SSH in a normal way and then do echo $PATH then I get the PATH which I have configured in /etc/profile:

/usr/local/bin:/usr/bin:/bin:/usr/games:/opt/maven/bin:/opt/ant/bin:/opt/mercurial/bin:/opt/git/bin

But when I do ssh user@server 'echo $PATH' instead then I get this:

/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games

The same happens when I use GIT or Mercurial with an ssh URL. It can't find hg or git executable on the server because it don't get the PATH from /etc/profile.

So the question is: Is there a "more global" way to configure the PATH so it also works with SSH remote execution? Configuring the PATH per user is not an option. Specifying the full path to git/hg executables when using git/hg on the client is also not an option. And I know that I could use symlinks or wrapper scripts in /usr/local/bin to get it working but I'm searching explicitly for a possibility to have a correct PATH when executing commands remotely via SSH.

A: 

While not an answer to your problem, from this link, it looks like ssh has a path settings of its own.

Raghuram
I guess this information is outdated (13 years old). I don't have a duplicate /usr/bin and I have /usr/bin/X11 in the SSH default path. But whatever, I can't find any hints in the sshd man page about path. So maybe it is really a "fixed" (hardcoded) path like mentioned in this old howto. Or maybe this path is read from somewhere else. I grepped the whole /etc directory but can't find anything except /etc/profile.
kayahr
+1  A: 

The ssh server set some environment variables at the start of the session. You can create a ~/.ssh/environment file on the ssh server to set additional variables (assuming there is a BSD openssh server on the server), but the server must be configured to allow to change the environment.

If the above doesn't work, you can set the remote command. In mercurial this is the --remotecmd switch for push and pull.

Rudi
+2  A: 

On Debian, the standard environment is setup through pam_env (in /etc/pam.d/sshd), which will read /etc/environment and /etc/security/pam_env.conf. You can either edit those, or you add another pam_env line to the pam configuration, pointing to an environment file specific to SSH logins.

Martin v. Löwis