4

I know what should be the difference between su and su -, but in my system (Debian) 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 think that the settings can be changed in configuration files.

4
  • 3
    Please see unix.stackexchange.com/questions/7013/…
    – jsbillings
    Feb 23, 2011 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, 2011 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, 2011 at 20:59
  • Note that Debian people have changed the su program since this question was written and answered. unix.stackexchange.com/q/460478/5132
    – JdeBP
    Feb 21, 2019 at 16:12

2 Answers 2

5

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.

4

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.

You must log in to answer this question.

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