Previous Section  < Day Day Up >  Next Section

Recipe 8.20. Using su to Be Root Temporarily

8.20.1 Problem

Like all good Linux users, you understand the importance of using the least necessary privileges to get a job done. You know that root is all-powerful, so you run as root only when absolutely necessary. How do you temporarily switch to root when you need to?

8.20.2 Solution

Use the su, or "switch user," command when you need to do system chores:

carla@windbag:~$ su



Then go back to being yourself:

root@windbag:/home/carla# exit



To change to root and invoke root's shell and environment settings use:

carla@windbag:~$ su -



To change to a different shell use:

$ su - —shell=tcsh


Available shells are listed in /etc/shells.

8.20.3 Discussion

You can change to any user, as long as you have the password.

The dash after su makes a world of difference. Without it, you're still in your own system environment, using your environment variables—shell, default editor, paths, and umask.

8.20.4 See Also

  • su(1)

    Previous Section  < Day Day Up >  Next Section