Skip to main content

Review exercises


Table of contents

  1. Validation quiz
  2. Exercise 1: User management
  3. Exercise 2: Permissions
  4. Mini-project: Configure an application user
  5. Next steps


1 - Validation quiz

Questions

Q1. Which command adds a user to a group without removing them from other groups?

See the answer

usermod -aG groupe utilisateur

The -a (append) is crucial! Without it, the user is removed from all their existing groups.


Q2. What are the octal permissions for rwxr-xr--?

See the answer

754

  • rwx = 4+2+1 = 7
  • r-x = 4+0+1 = 5
  • r-- = 4+0+0 = 4

Q3. How do you edit the sudoers file securely?

See the answer

visudo or sudo visudo

Visudo checks the syntax before saving, avoiding breaking sudo.


Q4. What is the difference between apt remove and apt purge?

See the answer
  • apt remove: deletes the package but keeps the configuration files
  • apt purge: deletes the package AND the configuration files

Q5. How do you kill a process that is not responding?

See the answer

kill -9 PID or kill -SIGKILL PID

Signal 9 (SIGKILL) forces immediate termination.


Q6. How do you enable a service at boot AND launch it immediately?

See the answer

sudo systemctl enable --now service


Q7. How do you make an environment variable permanent for a user?

See the answer

Add export VARIABLE=valeur to ~/.bashrc then run source ~/.bashrc


Q8. How do you redirect stdout AND stderr to the same file?

See the answer

commande > fichier.txt 2>&1 or commande &> fichier.txt


Q9. What is the tee command used for?

See the answer

tee splits the output: it writes to a file AND displays it on screen at the same time.


Q10. How do you view the logs of a systemd service in real time?

See the answer

journalctl -u service -f


Results

ScoreLevel
10/10Excellent! You are ready for Linux 3
7-9/10Good! Review the points you missed
4-6/10Average. Reread the relevant chapters
0-3/10Start the Linux 2 course over

🔝 Back to table of contents



2 - Exercise 1: User management

Goal

Create and configure a user with specific groups.

Instructions

# 1. Créez un groupe "developers"
sudo groupadd developers

# 2. Créez un utilisateur "devuser" avec :
# - Home directory
# - Shell bash
# - Membre du groupe developers
sudo useradd -m -s /bin/bash -G developers devuser

# 3. Définissez un mot de passe
sudo passwd devuser

# 4. Vérifiez la création
id devuser
# Devrait afficher : uid=...(devuser) gid=...(devuser) groups=...(devuser),...(developers)

# 5. Ajoutez devuser au groupe sudo
sudo usermod -aG sudo devuser

# 6. Vérifiez les groupes
groups devuser

# 7. Créez un fichier de test dans son home
sudo -u devuser touch /home/devuser/test.txt

# 8. Vérifiez le propriétaire
ls -la /home/devuser/test.txt

Verification

# L'utilisateur devuser doit :
# - Exister (id devuser ne doit pas afficher d'erreur)
# - Avoir /home/devuser comme home
# - Avoir /bin/bash comme shell
# - Être membre de developers et sudo

Cleanup

sudo userdel -r devuser
sudo groupdel developers

🔝 Back to table of contents



3 - Exercise 2: Permissions

Goal

Configure permissions for a shared project folder.

Instructions

# 1. Créez un groupe projet
sudo groupadd projet

# 2. Créez un dossier partagé
sudo mkdir /srv/projet

# 3. Changez le propriétaire et groupe
sudo chown root:projet /srv/projet

# 4. Configurez les permissions :
# - Propriétaire : rwx
# - Groupe : rwx
# - Autres : r-x
# + SGID pour que les nouveaux fichiers héritent du groupe
sudo chmod 2775 /srv/projet

# 5. Vérifiez
ls -ld /srv/projet
# drwxrwsr-x 2 root projet ... /srv/projet

# 6. Ajoutez votre utilisateur au groupe
sudo usermod -aG projet $USER

# 7. Reconnectez-vous (ou newgrp projet)
newgrp projet

# 8. Créez un fichier dans le dossier
touch /srv/projet/test.txt

# 9. Vérifiez que le fichier appartient au groupe projet
ls -la /srv/projet/test.txt

Questions

  1. Why do we use SGID (2)?
  2. What happens if you forget the SGID?
  3. Why do others have r-x and not rwx?
Answers
  1. SGID makes new files inherit the group of the directory
  2. Without SGID, created files would have the user's primary group
  3. r-x allows reading and accessing the folder without being able to modify/create

Cleanup

sudo rm -rf /srv/projet
sudo groupdel projet

🔝 Back to table of contents



4 - Mini-project: Configure an application user

Context

You need to configure a server to deploy a Node.js application. You will create a dedicated user with the correct permissions.

Objectives

  1. Create a deploy user without interactive access
  2. Create the folder structure
  3. Configure the permissions
  4. Create a simple systemd service

Instructions

# === ÉTAPE 1 : Créer l'utilisateur ===

# Créer l'utilisateur système (sans home standard, sans login)
sudo useradd -r -s /usr/sbin/nologin -d /app deploy

# Créer manuellement le répertoire
sudo mkdir -p /app
sudo chown deploy:deploy /app

# Vérifier
id deploy
ls -ld /app

# === ÉTAPE 2 : Structure de dossiers ===

sudo -u deploy mkdir -p /app/{current,releases,shared}
sudo -u deploy mkdir -p /app/shared/{logs,config}

# Vérifier la structure
ls -la /app
ls -la /app/shared

# === ÉTAPE 3 : Créer une application factice ===

# Créer un script simple
cat << 'EOF' | sudo tee /app/current/app.sh
#!/bin/bash
while true; do
echo "[$(date)] Application running..."
sleep 10
done
EOF

# Rendre exécutable
sudo chmod 755 /app/current/app.sh
sudo chown deploy:deploy /app/current/app.sh

# === ÉTAPE 4 : Créer le service systemd ===

cat << 'EOF' | sudo tee /etc/systemd/system/myapp.service
[Unit]
Description=My Application
After=network.target

[Service]
Type=simple
User=deploy
Group=deploy
WorkingDirectory=/app/current
ExecStart=/bin/bash /app/current/app.sh
Restart=always
RestartSec=5
StandardOutput=append:/app/shared/logs/app.log
StandardError=append:/app/shared/logs/app.log

[Install]
WantedBy=multi-user.target
EOF

# Recharger systemd
sudo systemctl daemon-reload

# === ÉTAPE 5 : Tester ===

# Démarrer le service
sudo systemctl start myapp

# Vérifier l'état
sudo systemctl status myapp

# Voir les logs
tail -f /app/shared/logs/app.log

# Arrêter pour nettoyage (Ctrl+C d'abord)
sudo systemctl stop myapp

Final checks

ItemVerification commandExpected result
Userid deployExists, no shell
/app folderls -ld /appOwned by deploy
Servicesystemctl status myappActive (running)
Logsls /app/shared/logs/app.log exists

Cleanup

sudo systemctl stop myapp
sudo systemctl disable myapp
sudo rm /etc/systemd/system/myapp.service
sudo systemctl daemon-reload
sudo rm -rf /app
sudo userdel deploy

🔝 Back to table of contents



5 - Next steps

Congratulations!

You have completed the Linux 2 - Basic Administration course!

What you have learned

Skills acquired

SkillMastery
Manage users and groups
Configure permissions
Use sudo securely
Install and manage packages
Monitor processes
Manage systemd services
Configure environment variables
Use redirections and pipes

Next step: Linux 3

In the Linux 3 - System and Network course, you will learn:

  • Advanced file system
  • Storage management (LVM, mounting)
  • Network configuration
  • SSH and secure connections
  • Firewall (UFW, iptables)
  • Scheduled tasks (cron)
  • Archiving and compression
  • Advanced search (find, sed, awk)

Tips for making progress

  1. Practice on VMs: Break things, fix them, start over
  2. Administer a real server: A cheap VPS to experiment
  3. Automate: Write scripts for repetitive tasks
  4. Read the logs: Get used to journalctl
  5. Document: Note down what you learn

Command summary

Users and groups

CommandUsage
useradd -m -s /bin/bash userCreate a user
usermod -aG groupe userAdd to a group
passwd userSet the password
id userUser information

Permissions

CommandUsage
chmod 755 fichierModify permissions
chown user:group fichierChange the owner
ls -laView permissions

Packages

CommandUsage
apt update && apt upgradeUpdate
apt install packageInstall
apt remove packageRemove

Processes and services

CommandUsage
ps auxList processes
kill -9 PIDForce stop
systemctl start/stop/statusManage services
journalctl -u service -fLogs in real time

Redirections

SyntaxUsage
>Redirect stdout (overwrites)
>>Redirect stdout (appends)
2>Redirect stderr
|Pipe
teeSplit the output

🔝 Back to table of contents


← Previous chapter | Back to table of contents →