Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Why does Linux use the sudo command?

+2
−4

Why does Linux use the sudo command?

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

Very vague question (1 comment)

1 answer

+4
−2

In Unix systems like Linux, some commands are considered dangerous and only the root user can run them. Normally, you don't login as root. So when you want to run dangerous commands, you must first become root. Then you run your dangerous stuff, and go back to your own user.

This switching between users is tedious and many people don't like it. So the sudo command was created to automate the process. sudo some_command is equivalent to:

1. Log out
2. Log in as root
3. Run some_command
4. Log out
5. Log in as your normal user

But it is nicer because it inherits most of your user environment. For example, sudo ls ~ is smart enough to print the contents of your actual home directory, instead of the root's home directory. This is because logging in as root would set environment variables like $HOME to root's home (/root), but sudo doesn't use the normal interactive login and does not change your $HOME from the value corresponding to your normal user. There are many other small details like this that sudo avoids for you.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

`sudo ls ~` will not tell you whether `sudo` sets `HOME`, because the `~` is expanded by the non-root... (3 comments)

Sign up to answer this question »