Chapter 4: Users and Groups

Foreword

We recommend that you do not use AI to do the exercises because you are in the learning phase.

Introduction

Linux is a true multi-user system! Multiple users can log in and perform tasks at the same time. It also has a single-user mode managed by the kernel, used only for maintenance purposes. Users generally have:

Prerequisites (Repetition is educational 😜)



User management

Intro

To test πŸ‘¨πŸΎβ€πŸ’»πŸ‘©πŸΎβ€πŸ’»:

A quick explanation.

Command: whoami

widal@j4rd1n-d3s-0mbr3s:~$ whoami
widal

What is the /etc/passwd file?

πŸ”πŸƒ UNO Reverse!!!

widal@j4rd1n-d3s-0mbr3s:~$ echo β€œuser avrell is there” user avrell is there widal@j4rd1n-d3s-0mbr3s:~$



### 1. `useradd` – Add a new user
```bash
sudo useradd username
sudo usermod -d /new/path alice

Changes alice’s home directory.


3. passwd – Change a user’s password

sudo passwd username

4. userdel – Delete a user

sudo userdel username

adduser vs useradd

Command Description
useradd Low-level command: simple, but requires more options.
adduser Interactive script: step-by-step guide to creating a user (password, info, home folder, shell, etc.).

Example:

sudo adduser bob

This launches a wizard to create a complete user.

⚠️ ADDITIONAL INFO:

There may be a downside (usually when using useradd) and your user may end up without a home directory. You can fix this with the mkhomedir_helper command. (e.g., mkhomedir_helper myuserbob).


TLDR (Quick summary)

| Command | Role | |————–|———————————–| | useradd | Create a user (simple) | | adduser | Create a user (assisted) | | usermod | Modify an existing user | | passwd | Change the password | | userdel | Delete a user | | mkhomedir_helper | Create a user’s home directory |

Commands to change users

Exercise βš”οΈ

Below is an example of execution:

# Download the challenge script 1
curl -LO https://raw.githubusercontent.com/N0vachr0n0/NoFD/refs/heads/main/USER_EXO_1.sh
# Make it executable
chmod +x USER_EXO_1.sh
# Run it to start the challenge
./USER_EXO_1.sh

Group Management

Intro

To test πŸ‘¨πŸΎβ€πŸ’»πŸ‘©πŸΎβ€πŸ’»:

groups #To see the group(s) you belong to id #To see your primary group and secondary groups


* The **/etc/group** file lists all the groups in the system and their associated information
* Like **/etc/passwd**, it is common to all distributions
  
* It is also a public file that anyone can read
* **/etc/group** nomenclature:

groupname:grouppassword:gid:userlist

   * Example:
    ```
    admins:x:10:djo,jack,william,avrell
    ```
* As with users, the root group always has the gid 0!
**To test πŸ‘¨πŸΎβ€πŸ’»πŸ‘©πŸΎβ€πŸ’»:**
- Open your terminal
- Run:
```bash
cat /etc/group

The x that you will see here again represents the group password. It is located in /etc/gshadow, and as for users in /etc/shadow:

Group management commands

⚠️ Don’t forget the important points ⚠️

Managing the /etc/sudoers file

The /etc/sudoers file is a configuration file used on Linux/Unix systems to define user and group permissions for using the sudo command. It determines who can execute commands as the administrator (root) or another user, and which specific commands they can execute.

This file is crucial for security, as misconfiguration can either block legitimate access or grant too many privileges.

To finish off, I invite you to do some research on:

sudo -l



Exercise βš”οΈ

Run the script to start the challenge like a pro πŸ˜‰.

πŸ‘‰πŸΎ Click here