Linux Mall - The Linux SuperStore!
Linux books, Linux CDs, Linux toys, you name it, they have it!

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

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 wide-open to hackers? I think not.

[ Home ] [ Contents ] [ Download*] [ Previous ] [ Next ]
* In Linux enter: unzip nlm.zip
Homepage | The Last 5 Days | The Daily Linux News | The Linux Bits | Newbie's Linux Manual
The Best Linux Sites | Linux Book Reviews | A Windows Vendetta?
Diary of a Linux Newbie | Diary of an Open Source Newbie
The Linux Forum | Just For Fun
Amazon - The World's Biggest Bookstore!
4.7 million books, CDs, videos, and DVDs available to buy!
© MM Linuxdot.org | Webmaster | Manual's Copyright Terms