1

When I'm logged in my ArchLinux server and type:

$echo $PATH
I get...
/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/bin/core_perl

But when I'm NOT logged in and try:

ssh myyser@mysever 'echo $PATH'
i get..
/usr/bin:/bin:/usr/sbin:/sbin

The PATH is correct in my /etc/profile but ssh seems to not load that.

Is there any way to fix it for all users/ssh sessions?

It does not happen when i using ubuntu

Posting here as suggested by Eugene Mayevski 'EldoS Corp

4 Answers4

1

If you're using Bash as the default shell for the user, your ssh command starts a non-interactive non-login shell so it doesn't process /etc/profile. You will need to source that file in your script.

Dennis Williamson
  • 62,149
  • 16
  • 116
  • 151
1

When you run a command via ssh, it does not start a login shell on the remote host. The practical implications of this vary, but typically it means that shell initialization files that run at login will be ignored. On the other hand, shell initialization files that for every shell instance will still be processed.

If you're using bash, this means that only your .bashrc file is used. I often put something like this in my .bashrc file:

if [ ! "$RAN_PROFILE" ]; then
  . $HOME/.profile
fi

And in the bottom of my .profile:

RAN_PROFILE=1
export RAN_PROFILE

This ensures that I get .profile services even for non-login shells.

larsks
  • 43,623
  • 14
  • 121
  • 180
1

I fixed this issue adding the path into /etc/environment

PATH=/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/bin/core_perl

Don't know if this is a good practice, but is working.

Thank you!

  • It's perfectly acceptable to 'accept' your own answer if it fixes the problem. You won't get rep, but it lets the system know that the problem is resolved, and later viewers may upvote it when it helps them. – sysadmin1138 Feb 06 '11 at 23:11
  • sorry, but how can i mark this question as resolved? – Alexandre Bini Feb 07 '11 at 00:02
0

The shell on your client expands the PATH variable, so you'll need to escape the dollar sign.

foo$ ssh username@bar.example.com 'echo \$PATH'

Alex Holst
  • 2,240
  • 1
  • 15
  • 13