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

1

4 Answers 4

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.

1
  • is there any other way? I'm asking because its working on ubuntu, maybe is an Archlinux problem... Feb 6, 2011 at 18:30
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.

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!

2
  • 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 6, 2011 at 23:11
  • sorry, but how can i mark this question as resolved? Feb 7, 2011 at 0:02
0

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

foo$ ssh [email protected] 'echo \$PATH'

2
  • Not when it's inside single quotes. Your command will echo "$PATH" literally. Feb 6, 2011 at 18:09
  • Well, that was a silly mistake to make.
    – Alex Holst
    Feb 6, 2011 at 18:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .