Commandline 101: su and sudo

April 23rd, 2009 by Shawn Powers in

Your rating: None Average: 4.4 (7 votes)

How to change your root password and use the su command in Ubuntu.

Download in .ogv format
__________________________
Shawn Powers is an Associate Editor for Linux Journal. You might find him chatting on the IRC channel, or Twitter


Special Magazine Offer -- Free Gift with Subscription
Receive a free digital copy of Linux Journal's System Administration Special Edition as well as instant online access to current and past issues. CLICK HERE for offer

Linux Journal: delivering readers the advice and inspiration they need to get the most out of their Linux systems since 1994.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
dalesmcd's picture

su

On April 25th, 2009 dalesmcd (not verified) says:

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.

Manson Thomas's picture

What's the use of setting root password ?

On April 25th, 2009 Manson Thomas (not verified) says:

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.

Anonymous's picture

Not to be nit-picky, but....

On April 24th, 2009 Anonymous (not verified) says:

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!

waparmley's picture

Other Ways

On April 24th, 2009 waparmley says:

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!

susos's picture

another

On April 24th, 2009 susos (not verified) says:

sudo -s ?

Anonymous's picture

An easier way....

On April 23rd, 2009 Anonymous (not verified) says:

Use sudo -i for an interactive root shell.

groggyboy's picture

two other commands that

On April 23rd, 2009 groggyboy (not verified) says:

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.

Shawn Powers's picture

Huh.

On April 23rd, 2009 Shawn Powers says:

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

Salvadesswaran Srinivasan's picture

Nice video this

On April 24th, 2009 Salvadesswaran Srinivasan (not verified) says:

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

Please note that comments may not appear immediately, so there is no need to repost your comment.
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <pre> <ul> <ol> <li> <dl> <dt> <dd> <i> <b>
  • Lines and paragraphs break automatically.

More information about formatting options

Newsletter

Each week Linux Journal editors will tell you what's hot in the world of Linux. You will receive late breaking news, technical tips and tricks, and links to in-depth stories featured on www.linuxjournal.com.
Sign up for our Email Newsletter

Tech Tip Videos

From the Magazine

December 2009, #188

If last month's Infrastrucuture issue was too "big" for you then try on this month's Embedded issue. Find out how to use Player for programming mobile robots, build a humidity controller for your root cellar, find out how to reduce the boot time of your embedded system, and if you're new to embedded systems find out the basics that go into one. You can also read about the Beagle Board, the Mesh Potato and a spate of other interestingly named items. And along with our regular columns don't miss our new monthly column: Economy Size Geek.







Read this issue