5

I thought that using su as a regular user made you root temporarily, but encountered an issue where I get "bash: usermod: command not found" when I try to perform a usermod with su, whereas the command definitely exists when I log in as root.

Are super user and root different things? If so, what limitations should I be aware of?

2
  • 3
    sudo is there to protect you from yourself as it is too easy to make mistakes running as root. I've been a unix-head since way before sudo, never make an rm I didn't mean, and still use sudo in preference to a root shell. Typing 4 characters, a space, and sometimes my user password requires far more awareness of root privilege than having # as a shell prompt.
    – msw
    Jul 6, 2010 at 22:07
  • 1
    @msw: true, but sometimes sudo is unnecessarily inconvenient, e.g. when you're going to be running a series of commands as root or you want to take advantage of filename completion in rwx------ directories, or something like that. What I do is set the root shell prompt to display in red and my regular user's shell prompt to display in green. Works great and it's pretty too ;-) (and I do usually use sudo too)
    – David Z
    Jul 7, 2010 at 4:11

1 Answer 1

12

There's no difference between "the super user" and "root". But the thing is, su (which actually stands for "switch user", I believe) doesn't entirely emulate the environment you would get if you logged in directly as root. For instance, usually when you run su, environment variables from your current shell are carried over to the subshell in which you're logged in as root. (Except for PATH; see the man page for details)

To get around this, you can use the -l (or --login) option to su, which will attempt to duplicate the environment you would get if you actually logged in as root.

9
  • 10
    +1, right answer. I typically use just the dash instead: su -. Check your su man page to verify that su - and su -l act the same on your system. Jul 6, 2010 at 20:45
  • 3
    +1 for switch user. Not many people remember that it can be used for any username if you're in wheel.
    – AndrejaKo
    Jul 6, 2010 at 21:14
  • @AndrejaKo: regarding /in wheel/ - does any su check that? (I know GNU version ignores wheel completely.) Jul 7, 2010 at 12:00
  • I honestly don't know. I think that in Solaris it does, but I can't test it at the moment. I remember I read that back when GNU su was new, rms decided not to use wheel because of ideological reasons. I assume that at the time Unix systems regularly checked to see if user was in wheel. Also I read somewhere that Solaris will use wheel if group exists. Here's a source for that windowsecurity.com/whitepapers/Armoring_Solaris.html
    – AndrejaKo
    Jul 7, 2010 at 12:34
  • 1
    @Yarin: actually there is: sudo -i will simulate an initial login by invoking the shell of the specified user (root by default) as a login shell. This should have mostly the same effect as su -l but it's a different mechanism, so it might not be exactly the same down to every detail. See the man page for sudo for details.
    – David Z
    Jul 9, 2010 at 0:14

You must log in to answer this question.

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