> For the complete documentation index, see [llms.txt](https://cybersecurity-cloud-and-it-notes.gitbook.io/kyles-cybersecurity-cloud-and-it-gitbook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cybersecurity-cloud-and-it-notes.gitbook.io/kyles-cybersecurity-cloud-and-it-gitbook/google-cybersecurity-professional-cert/4.-linux-and-sql-tool-of-the-trade/module-3/authenticate-and-authorize-new-users/responsible-use-of-sudo.md).

# Responsible use of Sudo

#### 🚀 Fun & ADHD-Friendly Notes on Responsible Use of Sudo & Managing Users in Linux! 🧑‍💻

***

#### 🔑 **Sudo = Super Powers**

* **Sudo** stands for **Super User Do**, which temporarily gives you **elevated privileges** to run specific commands **without** logging in as root (aka superuser).
* **Root users** are powerful but risky! Using root directly can lead to irreversible mistakes or make it easy for hackers to target your system. 👀
* **Sudo** is like having a **master key** in a hotel 🏨. It lets you access specific rooms (or commands) when you need to, but if a hacker steals your key, it's bad news. That’s why **sudo** should be handled **with care**! 🛡️

***

#### ⚔️ **The Sudo Command in Action**

* Only give **sudo** access to people who really need it (less risk of accidents or attacks!).
* **Be mindful** of sudo when you copy commands from online sources—don’t accidentally run sudo on commands that don’t need it. 🚫

***

#### 🧑‍💻 **Managing Users & Groups with Sudo**

**1️⃣ Add a user:**

Use the `useradd` command to bring a new user into the system.

* Example:

  ```bash
  sudo useradd fgarcia
  ```

  * You can add them to a **primary group** with `-g` or **supplemental groups** with `-G`.
  * Example:

    ```bash
    sudo useradd -g security -G finance fgarcia
    ```

**2️⃣ Modify an existing user:**

Use `usermod` to change user details like groups or directories.

* **Change group**:

  ```bash
  sudo usermod -g executive fgarcia
  ```
* **Add to supplemental group** (without removing other groups):

  ```bash
  sudo usermod -a -G marketing fgarcia
  ```

**3️⃣ Delete a user:**

* **Delete the user**:

  ```bash
  sudo userdel fgarcia
  ```
* **Delete user AND their home directory** with `-r`:

  ```bash
  sudo userdel -r fgarcia
  ```
* **Lock the account** if you don’t want to delete it right away:

  ```bash
  sudo usermod -L fgarcia
  ```

***

#### 👑 **Changing File Ownership with chown**

* **chown** changes file or directory ownership (either user or group).
* Change file owner:

  ```bash
  sudo chown fgarcia access.txt
  ```
* Change group owner:

  ```bash
  sudo chown :security access.txt
  ```

***

#### 🚨 **Key Takeaways**

* **Authentication**: Verifying identity 🕵️‍♂️.
* **Authorization**: Deciding who gets access to what 🗝️.
* **Sudo** gives temporary elevated access without using root! It’s safer.
* Use **useradd**, **usermod**, **userdel**, and **chown** to manage users, groups, and file ownership.

***

**Be the wise master of sudo** 🧙‍♂️—use your superpowers responsibly, and you’ll keep your system safe and running smoothly! 🖥️✨
