Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I know what should be the difference between su and su -, but in my system (debian testing) for example PATH is the same:

[root]# su
[root]# echo $PATH
/user_path/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
[root]# exit
[root]$ su -
[root@debian ~]# echo $PATH
/user_path/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

So I'm starting to thinki that the difference can be changed in configuration files.

share|improve this question
3  
Please see unix.stackexchange.com/questions/7013/… –  jsbillings Feb 23 '11 at 18:08
1  
They're the same because the path for your normal user is already the same as that for root. –  mattdm Feb 23 '11 at 19:38
    
What distribution/operating system? The exact answer depends, for example the defaults are different for Red Hat/Fedora and Debian/Ubuntu. –  Mikel Feb 23 '11 at 20:59
add comment

2 Answers

up vote 5 down vote accepted

For configuring the su PATH, have a look at /etc/login.defs:

ENV_SUPATH      PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ENV_PATH        PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

There are also a number of other places PATH can be changed, including:

  • /etc/environment
  • /etc/bash.bashrc
  • /etc/profile
  • /etc/profile.d/*
  • ~/.bashrc
  • ~/.bash_profile

Without anything special in per-user settings, su seems to be getting its PATH from /etc/environment and su - seems to be getting its environment from /etc/login.defs ENV_SUPATH.

So on your system, my guess is that you have the same PATH value in /etc/login.defs as in /etc/environment, or you have some extra configuration in /etc/profile.d, /etc/bash.bashrc, or some rc file in /home/someuser.

share|improve this answer
add comment

Parameter - means starting environment which is almost the same as with login environment for that user.

Without - environment is same as original user's environment.

For example PATH is usually same for root and normal users. In some systems there is no sbin folders for normal users. You can't disable - from su easily. Of course you can go to edit the source code.

You can try this by running

export FOO=bar
su # enter your password
echo $FOO
logout
su - # enter your password again
echo $FOO

In first time echo $FOO prints "bar" and in second time it's empty.

share|improve this answer
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.