Post History
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...
Answer
#3: Post edited
- 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
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 account2. Run dangerous command3. 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.