## root vs su vs sudo
Let's delve into the concepts of **root**, **sudo**, and **su** in the context of Linux systems:
1. **Root User (Superuser)**:
- The **root user** is the **superuser** in a Unix-like operating system (including Linux). It has **full administrative privileges** and can perform any action on the system.
- Root can:
- Install and uninstall software.
- Modify system files.
- Change system configurations.
- Access all files and directories.
- However, due to security concerns, it's generally recommended to avoid using the root account directly for everyday tasks.
2. **su (Switch User)**:
- The `su` command (short for **substitute** or **switch user**) allows you to **run commands with another user's privileges** (usually the root user).
- Common usage:
- To switch to the **administrative account** (root) within the current login session.
- Example: `su`
- You'll be prompted to enter the root password.
- If authenticated, you temporarily become root.
- The session shell and environment variables are set from the root user's `/etc/passwd` entry.
- Confirm the user change with `whoami` (it should display "root").
- Options:
- `-` (or `-l`, `--login`): Makes the shell a **login shell** with an environment similar to a real login.
- `-s, --shell`: Specify a different shell (e.g., `su -s /bin/sh`).
- `-p, --preserve-environment`: Preserve the entire environment of the calling user.
- `-c, --command`: Run a command as the substitute user (without starting an interactive shell).
3. **sudo (Superuser Do)**:
- The `sudo` command allows users to run programs as another user (usually root) without directly logging in as root.
- Key points:
- More secure than `su`. As, su will start an interactive shell with root access (unless not specified with -c ```command```)
- Grants **temporary root privileges** to users.
- Example: `sudo su -`
- Enter the currently logged-in user's password.
- Effectively switches to root.
- `-i`: Run an interactive login shell with the root user's environment (similar to `su -`).
4. **Differences**:
- `su` vs `sudo`: requires the root password and switches to interactive terminal with root access `by default`, while `sudo` uses the user's password and elevates permissions to root access to perform any operation without switching to an interactive terminal with root access `by deafult`.
Remember, **security matters**! Use `sudo` wisely and avoid unnecessary root access to maintain system integrity.