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

Post History

60%
+4 −2
Q&A Why does Linux use the sudo command?

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...

posted 3mo ago by matthewsnyder‭  ·  edited 3mo ago by matthewsnyder‭

Answer
#3: Post edited by user avatar matthewsnyder‭ · 2024-02-16T22:29:08Z (3 months ago)
  • 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 normally 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.
  • 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.
#2: Post edited by user avatar matthewsnyder‭ · 2024-02-16T06:12:39Z (3 months ago)
  • Short answer: In Linux, some commands are considered dangerous and can only be run by an admin account. `sudo` automates switching the process of:
  • ```
  • 1. Switch to admin account
  • 2. Run dangerous command
  • 3. Switch back
  • ```
  • 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 normally 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.
#1: Initial revision by user avatar matthewsnyder‭ · 2024-02-16T05:58:31Z (3 months ago)
Short answer: In Linux, some commands are considered dangerous and can only be run by an admin account. `sudo` automates switching the process of:
```
1. Switch to admin account
2. Run dangerous command
3. Switch back
```