Why do we use su - and not just su?
I understand that root doesn't have to be a superuser. But in the case that it is ... what is the difference between
sudo su - and
sudo su root?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
There are two questions there:
su - usernameand
-l) is specified,
su simulates a real login. The environment is cleared except for a few select variables (
XAUTHORITY on some systems). Otherwise the environment is left as it is except for
PATH that is reset.
This might be system-dependent. On Linux with
shadow as the package providing
su, if no username is specified, then
su first tries to see if user
root has a
passwd entry. If it does, it uses that. If it doesn't, it tries
Not sure about other Unix-like operating systems.
su - switches to the superuser and sets up the environment so that it looks like they logged in directly.
su root switches to the user named root and doesn't simulate directly logging in.
If the superuser is named root, then
su root are equivalent (and don't simulate directly logging in), as are
su - and
su - root (which do).