Commandline 101: su and sudo
How to change your root password and use the su command in Ubuntu.
Linux Journal is the premier source for how-tos, projects, product reviews, expert advice and opinions for everything Linux.
| We're Linux, Again | Feb 09, 2010 |
| Quick Compiz Screenshots | Feb 09, 2010 |
| Welcome to the New LinuxJournal.com | Feb 09, 2010 |
| Symbian Opens Up | Feb 04, 2010 |
| The Small Picture: More OpenOffice.org Extensions | Feb 04, 2010 |
| Pass the Bug, Collect $500 | Feb 02, 2010 |
This week 5 lucky Members will receive a copy of The Official Ubuntu Server Book by Benjamin Mako Hill and Linux Journal's very own Kyle Rankin. No entry necessary. Check back here early next week to find out who the lucky Online Members are.
Linux Journal, currently celebrating its 16th year of publication, is the original magazine of the global Linux community, delivering readers the advice and inspiration they need to get the most out of their Linux systems.
In-depth information provides a full 360-degree look at featured topics relating to Linux, giving a comprehensive source of everything readers need for creating and completing their own projects -- not just tools they will use today, but relevant and encompassing information they will turn to in future months and years. In addition to how-to content, Linux Journal includes opinions, new product information, profiles of leaders making major contributions in Open Source and product reviews. It also covers business, social and technical news and developments in order to fulfill its mission as the central forum and advocate for the greater Linux community throughout the world.

Comments
su
su doesn't mean super user. su means switch user or substitute user. Since most people use su only for root and since sudo means super user do, it's assumed su mean super user. But you can use su to run as any user, like $ su - bob. If you don't specify a user it assumes root.
What's the use of setting root password ?
Ok, it's shorter to type
#su -
than
#sudo -s
but it's only 3 characters more, in both case you type a password.
And by setting root a password, you need to remember one more (what's the use to set the same password of your current user?).
Which (root password) can be break while before I don't think it could be.
Maybe the best way to get root access is (I type sudo -s.... I can use a keyboard ;)) :
alias s="sudo -s"
type s (yahooo... you save one character lazy boy ;)) and type your current user password.
To my mind, setting a password to root is breaking a security concept of Ubuntu system (as you'd be able to break root password).
Thomas.
Not to be nit-picky, but....
I love Shawn's tech tips. Much better than the droll ones from "the other guy" (I forget his name...lol).
However, one correction...Shawn said su means "Super User". It actually means Substitute User. Allowing you substitute the current uid and gid with that of "USER":
SU(1) User Commands SU(1)
NAME
su - run a shell with substitute user and group IDs
SYNOPSIS
su [OPTION]... [-] [USER [ARG]...]
With no parameters, it defaults to root, but I use it quite often to substitute as a user if I need to do some things on behalf of the user. Of course, the most common use is to become root.
Cheers!
Other Ways
A couple of other ways to quickly get "superpowers." (Hey, wouldn't THAT be a cool nickname for Shawn Powers???"
The Ubuntu menu system includes "Root Terminal," although you need to enable it with Edit Menus, if I recall correctly.
In my installations I always create a launcher in the menus for "Root Nautilus" by using the command "gksudo nautilus". I very seldom resort to using this in the interest of system safety, but sometimes it's the quickest way to get something done.
My preferences for Nautilus include single click to select and small (67%) icons, so I leave root Nautilus set to double click and 100% size icons just to serve as a reminder that I'm operating as root and that I need to be extra careful!
another
sudo -s ?
An easier way....
Use sudo -i for an interactive root shell.
two other commands that
two other commands that accomplish the same thing are sudo su and sudo bash.
i added an alias to my bashrc file so that typing su actually executes one of those commands.
Huh.
Well look at that. I guess you can call me "LongForm McGee", since I apparently like to do things the long way.
Actually, maybe don't call me that. It'd be a weird nickname. :)
(Thanks for the tip though!)
Shawn Powers is an Associate Editor for Linux Journal. You might find him chatting on the IRC channel, or Twitter
Nice video this
Well Shawn I like your columns in LJ and the best thing I've done this month so far apart from recompiling my kernel and downloading Ubuntu 9.04 (for testing and tweaking, what else!) is adding LJ on twitter. Keep on the good work.
Post new comment