Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
add comment

4 Answers

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.

share|improve this answer
    
is there any other way? I'm asking because its working on ubuntu, maybe is an Archlinux problem... –  Alexandre Bini Feb 6 '11 at 18:30
add comment

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.

share|improve this answer
add comment

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!

share|improve this answer
    
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 '11 at 23:11
    
sorry, but how can i mark this question as resolved? –  Alexandre Bini Feb 7 '11 at 0:02
add comment

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'

share|improve this answer
    
Not when it's inside single quotes. Your command will echo "$PATH" literally. –  Dennis Williamson Feb 6 '11 at 18:09
    
Well, that was a silly mistake to make. –  Alex Holst Feb 6 '11 at 18:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.