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 comm开发者_如何学Cands remotely via SSH.
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.
While not an answer to your problem, from this link, it looks like ssh has a path settings of its own.
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.
I solved this issue by including all necessary files to the .bashrc
For instance:
. /etc/profile.d/rvm.sh
. /etc/profile.d/bash_completion.sh
精彩评论