LinuxMall.com Got Linux? CD Offer
Newbie's Linux Manual
Temporarily Becoming root: The su Command
by Laurence Hunter
[ Home ] [ Contents ] [ Download*] [ Previous ] [ Next ]
* In Linux enter: unzip nlm.zip
Like root, Only Better

Every now and again, you'll need to temporarily become root to perform a task or tasks that only root has the authority to perform. Instead of logging-off, moving to another machine, or switching to another "virtual terminal" (a very cool feature, discussed later) this can be done with the su command, which comes in the following two flavours:

su

If you enter su on its own (followed by the root password when prompted), you become root until you press Ctrl+D to log-out. Upon which, you will revert back to the account you were previously in.

However, because you almost never have to enter more than one command as root, and because of the similarities between this, and logging-in as root (remember my warning about this), the next offering is my recommended use of the su command.

Note

You can also enter: su username to swap to someone's account, e.g. su laurence (followed by the password for that account), although this is less common.

su -c 'command'

The great thing about using this method, is that once the one specific task is complete, you automatically revert back to the account you were previously using. Here's an example:

su -c 'mount /mnt/cdrom'

Wouldn't it be nice to forget you're currently root and accidentally issue a command that wreaks havoc? Or be on the Net and have your system open to hackers? I think not.

[ Home ] [ Contents ] [ Download*] [ Previous ] [ Next ]
* In Linux enter: unzip nlm.zip

W W W . L I N U X D O T . O R G

The Newbie's Linux Manual is reproduced on LinuxMall.com by permission. The Newbie's Linux Manual is written and maintained by Laurence Hunter. You can find much more of Laurence's work at his site: www.Linuxdot.org

© 1999 Linuxdot.org | Manual's Copyright Terms