Skip to main content

Review exercises


Table of contents

  1. Validation quiz
  2. Exercise 1: Network configuration
  3. Exercise 2: Secure SSH
  4. Mini-project: Secure SSH server
  5. Next steps


1 - Validation quiz

Questions

Q1. Which command displays inode usage?

See the answer

df -i


Q2. What is the difference between a symbolic link and a hard link?

See the answer
  • Hard link: same inode, same data
  • Symbolic link: special file pointing to a path

Q3. How do you automatically mount a partition at boot?

See the answer

Add an entry to /etc/fstab with the partition's UUID.


Q4. Which command displays the listening ports?

See the answer

ss -tulnp or netstat -tulnp


Q5. How do you copy an SSH key to a server?

See the answer

ssh-copy-id user@serveur


Q6. Which UFW rule allows SSH from a specific IP?

See the answer

sudo ufw allow from 192.168.1.100 to any port 22


Q7. What does the cron expression 0 */4 * * * mean?

See the answer

Every 4 hours, at minute 0 (0:00, 4:00, 8:00, 12:00, 16:00, 20:00)


Q8. How do you create a .tar.gz archive?

See the answer

tar -czvf archive.tar.gz dossier/


Q9. How do you find all files larger than 100 MB modified in the last 7 days?

See the answer

find / -type f -size +100M -mtime -7


Q10. How do you replace "foo" with "bar" in a file with sed?

See the answer

sed -i 's/foo/bar/g' fichier.txt


Results

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

🔝 Back to table of contents



2 - Exercise 1: Network configuration

Goal

Diagnose and document the network configuration of a system.

Instructions

# 1. Affichez toutes les interfaces réseau
ip a

# 2. Notez :
# - Nom de l'interface principale
# - Adresse IP
# - Masque de sous-réseau

# 3. Affichez la passerelle par défaut
ip route | grep default

# 4. Affichez les serveurs DNS
cat /etc/resolv.conf
# ou
resolvectl status

# 5. Testez la connectivité
ping -c 3 8.8.8.8 # Test IP
ping -c 3 google.com # Test DNS

# 6. Tracez le chemin vers google.com
traceroute google.com

# 7. Vérifiez les ports en écoute
sudo ss -tulnp

Deliverable

Create a file with your results:

cat << EOF > ~/network_info.txt
=== Configuration Réseau ===
Date: $(date)
Interface: [VOTRE_INTERFACE]
IP: [VOTRE_IP]
Masque: [VOTRE_MASQUE]
Passerelle: [VOTRE_GATEWAY]
DNS: [VOS_DNS]
=== Tests ===
Ping IP: OK/FAIL
Ping DNS: OK/FAIL
EOF

🔝 Back to table of contents



3 - Exercise 2: Secure SSH

Goal

Configure SSH with key-based authentication.

Instructions

# 1. Générez une clé ED25519 (si pas déjà fait)
ssh-keygen -t ed25519 -C "exercice-linux3"

# 2. Vérifiez les fichiers créés
ls -la ~/.ssh/

# 3. Vérifiez les permissions
stat ~/.ssh/
stat ~/.ssh/id_ed25519

# 4. Créez un fichier de configuration SSH
cat << EOF > ~/.ssh/config
# Configuration SSH - Exercice Linux 3

# Paramètres par défaut
Host *
ServerAliveInterval 60
ServerAliveCountMax 3
AddKeysToAgent yes

# Exemple d'alias (à personnaliser)
# Host mon-serveur
# HostName exemple.com
# User deploy
# Port 22
# IdentityFile ~/.ssh/id_ed25519
EOF

# 5. Sécurisez le fichier
chmod 600 ~/.ssh/config

# 6. Vérifiez
cat ~/.ssh/config

If you have a server available

# Copiez la clé
ssh-copy-id user@serveur

# Testez la connexion sans mot de passe
ssh user@serveur "echo 'Connexion SSH par clé réussie !'"

🔝 Back to table of contents



4 - Mini-project: Secure SSH server

Context

You need to configure a secure server with:

  • Firewall configured
  • SSH with keys only
  • Automated backup
  • Basic monitoring

Part 1: Firewall

# Script de configuration pare-feu
cat << 'EOF' > ~/setup_firewall.sh
#!/bin/bash

# Reset UFW
sudo ufw reset

# Politique par défaut
sudo ufw default deny incoming
sudo ufw default allow outgoing

# SSH (limité pour anti-brute-force)
sudo ufw limit ssh

# HTTP/HTTPS (si serveur web)
sudo ufw allow http
sudo ufw allow https

# Activer
sudo ufw enable

# Afficher le statut
sudo ufw status verbose
EOF

chmod +x ~/setup_firewall.sh
echo "Script créé: ~/setup_firewall.sh"

Part 2: Backup script

cat << 'EOF' > ~/backup_script.sh
#!/bin/bash

# Configuration
BACKUP_DIR="/var/backups/system"
DATE=$(date +%Y%m%d_%H%M%S)
RETENTION_DAYS=7

# Créer le dossier
sudo mkdir -p $BACKUP_DIR

# Backup des configs importantes
sudo tar -czf "$BACKUP_DIR/etc_backup_$DATE.tar.gz" /etc/

# Rotation
sudo find "$BACKUP_DIR" -name "*.tar.gz" -mtime +$RETENTION_DAYS -delete

echo "Backup terminé: etc_backup_$DATE.tar.gz"
echo "Fichiers dans $BACKUP_DIR:"
ls -lh $BACKUP_DIR/
EOF

chmod +x ~/backup_script.sh
echo "Script créé: ~/backup_script.sh"

Part 3: Cron task

# Ajouter au crontab (simulation)
cat << 'EOF'
# Ajouter cette ligne avec: crontab -e
# Backup quotidien à 3h du matin
0 3 * * * /home/$USER/backup_script.sh >> /var/log/backup.log 2>&1
EOF

Part 4: Monitoring script

cat << 'EOF' > ~/monitor.sh
#!/bin/bash

echo "=== Monitoring Système ==="
echo "Date: $(date)"
echo ""

echo "=== Espace disque ==="
df -h | grep -E "^/dev|Filesystem"

echo ""
echo "=== Mémoire ==="
free -h

echo ""
echo "=== Charge CPU ==="
uptime

echo ""
echo "=== Top 5 processus CPU ==="
ps aux --sort=-%cpu | head -6

echo ""
echo "=== Services critiques ==="
for service in ssh; do
if systemctl is-active --quiet $service; then
echo "$service: ACTIF"
else
echo "$service: INACTIF !"
fi
done

echo ""
echo "=== Dernières connexions ==="
last -n 5
EOF

chmod +x ~/monitor.sh
echo "Script créé: ~/monitor.sh"

Test the monitoring

./monitor.sh

🔝 Back to table of contents



5 - Next steps

Congratulations!

You have completed the Linux 3 - System and Network course!

What you have learned

Skills acquired

SkillMastery
File system and storage
Network configuration
Network diagnostics
Secure SSH
Firewall (UFW)
Scheduled tasks
Archiving and backup
Advanced search

Next step: Linux 4

In the Linux 4 - Bash Scripting course, you will learn:

  • Variables and types
  • Conditions and loops
  • Functions
  • Advanced text manipulation
  • Error handling
  • Professional DevOps scripts

Tips for making progress

  1. Practice the commands regularly
  2. Configure a real server (VPS, Raspberry Pi)
  3. Automate your repetitive tasks
  4. Read the logs to understand problems
  5. Document your configurations

Command summary

File system

CommandUsage
df -hSpace per partition
du -shFolder size
lsblkList the disks
mount/umountMount/unmount

Network

CommandUsage
ip aInterfaces
ip routeRoutes
ss -tulnpListening ports
ping/tracerouteDiagnostics

SSH

CommandUsage
ssh-keygenGenerate a key
ssh-copy-idCopy a key
scp/rsyncFile transfer

Security

CommandUsage
ufw enableEnable the firewall
ufw allow/denyRules

Automation

CommandUsage
crontab -eEdit cron
tar -czvfCreate an archive
CommandUsage
findFile search
grepText search
awk/sedText processing

🔝 Back to table of contents


← Previous chapter | Back to table of contents →