Skip to content
Tutorials Center
My learning

Topics

Lesson 37 of 37 ยท Projects and Practice

Practice: Linux Administration Scenarios with Solutions

Test yourself with realistic Linux administration scenarios on networking, firewalls, SSH, SELinux, logs, monitoring, cron and troubleshooting, with hints, solutions and self-check quizzes.

Reading about administration is not the same as doing it. This page gives you scenarios in the style of real incidents and of certification labs (RHCSA, LFCS, Linux+). Try each one before you open its solution: write the commands you would run, and explain why. The scenarios cover the chapters of this part of the track: networking, security, logs, monitoring, automation and troubleshooting.

To practise for real, use a disposable virtual machine (VirtualBox, a cloud instance you delete afterwards, or a container with systemd) that you can break freely. Never practise firewall or SSH changes on a server you cannot reach another way. Solutions are read-only commands; two runnable Python drills check your reasoning about subnets and cron.

How to use this page

  1. Read the scenario and write down your plan on paper first.
  2. Check the hint only if you are stuck.
  3. Compare your answer with the solution; focus on the why, not on matching commands exactly.
  4. Repeat the scenario on a VM and verify each result with a second tool.

Scenario 1: the server that cannot resolve names

A new VM can ping 1.1.1.1 but ping example.org says "Temporary failure in name resolution".

Hint: IP connectivity works, so routing is fine. Which layer converts names?

Solution: check how names resolve, then fix the source of the resolver settings.

Terminal
getent hosts example.org                  # fails: the whole path is broken
ls -l /etc/resolv.conf                    # a symlink to the stub file?
resolvectl status                         # are there DNS servers on the link?
dig @1.1.1.1 example.org +short           # does the network allow DNS at all?
sudo resolvectl dns ens3 1.1.1.1 9.9.9.9  # test fix
# permanent: set nameservers in netplan / nmcli, then apply

See DNS and Name Resolution. If dig @1.1.1.1 also fails, a firewall blocks outbound port 53 and you must look at the egress rules.

Scenario 2: allow a web server, safely

You must open HTTPS on a remote Ubuntu machine that currently has no firewall, allow SSH only from the office network 203.0.113.0/24, and keep everything else closed.

Solution:

Terminal
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow from 203.0.113.0/24 to any port 22 proto tcp
sudo ufw allow 443/tcp
sudo ufw enable
sudo ufw status numbered

The SSH rule comes before enable. From outside the office network, confirm that port 22 is closed while 443 answers. If you worked from home, you would lock yourself out, which is exactly why you check your own source address first. Compare nftables and firewalld versions in Firewalls.

Python Subnet drill: is the host inside the allowed range?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Scenario 3: an SSH key login is refused

You copied your key with ssh-copy-id, but ssh alice@server still asks for a password (or says permission denied).

Hint: look at the server's side permissions, the effective configuration and the log.

Solution:

Terminal
ssh -v alice@server                        # client: which keys were offered?
# on the server (console or another admin):
ls -ld ~alice ~alice/.ssh ~alice/.ssh/authorized_keys
sudo chmod go-w ~alice; chmod 700 ~alice/.ssh; chmod 600 ~alice/.ssh/authorized_keys
sudo sshd -T | grep -E 'pubkeyauth|allowusers|authorizedkeysfile'
sudo journalctl -u ssh -n 30
sudo restorecon -Rv ~alice/.ssh            # on SELinux systems

The usual culprits: a home directory or .ssh writable by the group, a wrong owner, AllowUsers without alice, or a key that was pasted with a line break. See Remote Access with SSH.

Scenario 4: Apache cannot read the new document root

On a Rocky Linux server you moved a site to /srv/site. Permissions are 755, yet Apache returns 403 and the error log says "Permission denied".

Solution: this has the signature of SELinux. Confirm, then fix the label permanently.

Terminal
ls -Zd /srv/site                           # type default_t instead of httpd_sys_content_t
sudo ausearch -m AVC -ts recent
sudo semanage fcontext -a -t httpd_sys_content_t "/srv/site(/.*)?"
sudo restorecon -Rv /srv/site

Do not run setenforce 0 as the fix; use permissive mode only to confirm the theory. Details in Mandatory Access Control.

Scenario 5: find the brute-force attacker

Your SSH log is noisy. List the ten addresses with the most failed logins in the last day, then ban the worst one temporarily.

Solution:

Terminal
journalctl -u ssh --since "24 hours ago" --no-pager \
  | grep "Failed password" \
  | sed -E 's/.* from ([0-9.]+) port.*/\1/' \
  | sort | uniq -c | sort -rn | head -10
sudo fail2ban-client set sshd banip 198.51.100.77
sudo fail2ban-client status sshd

The long-term fix is key-only authentication (SSH hardening); banning is housekeeping.

Scenario 6: the cron job that never runs

You added 30 2 * * * backup.sh to a user's crontab. The backups are missing.

Hint: three separate problems are hiding in this line.

Solution: cron's PATH does not contain your script's directory, the script may not be executable, and the output goes nowhere. Use an absolute path, check execution permissions, log the output and confirm the daemon is running.

Terminal
30 2 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1
chmod +x /usr/local/bin/backup.sh
systemctl status cron                      # crond on the RHEL family
journalctl -u cron --since today | grep backup
Python Cron drill: when does it fire?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

See cron and timers for the syntax and pitfalls.

Scenario 7: the disk is full but nothing is big

df -h shows /var at 100 percent. du -sh /var/* adds up to less than half of it.

Solution: suspect deleted-but-open files and inode exhaustion.

Terminal
df -h /var; df -i /var
sudo lsof +L1 | head
sudo journalctl --disk-usage
sudo systemctl restart the-process-holding-the-deleted-file

Prevent the next one with log rotation and an alert that predicts the disk filling (alerting); the diagnosis tree is in the troubleshooting playbook.

Scenario 8: sluggish server, low CPU

Users report slowness. top shows 5 percent user CPU but load average 9 on a 4-core machine.

Solution: high load with idle CPU means tasks are waiting, usually for I/O. Check top for wa, run vmstat 2 5 (look at b and wa), iostat -xz 2 3 (await, %util) and iotop -oP. Find the process in state D: ps -eo pid,stat,comm | awk '$2 ~ /D/'. Typical cause: a slow disk, an overloaded backup job, or a stuck network mount. See Performance Monitoring.

Scenario 9: design question

You inherit twelve servers configured by hand. Describe in five steps how you would bring them under control.

A model answer: (1) inventory them and record versions and listening ports (ss -tulpn); (2) put a baseline in version control as an Ansible playbook for users, SSH, firewall and updates; (3) run it in --check --diff mode to see the drift; (4) apply to one server, then in small batches; (5) add monitoring and a scheduled convergence run so drift is detected. See Ansible and the hardening project.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Scenario: HTTPS must be open, SSH only from one office range. What must you do before ufw enable?

    Enabling a default-deny firewall without a rule for your session cuts you off.
  2. 2. A file has mode 644 but Apache still gets permission denied on SELinux. The first diagnostic is:

    The label, not the Unix permissions, is probably wrong.
  3. 3. Load is 9 on 4 cores with 5 percent user CPU. What is most likely?

    Tasks in uninterruptible sleep count toward load without using CPU.
  4. 4. Why use ssh -v when a key login fails?

    Verbose output reveals the authentication methods and key attempts, narrowing the cause.
  5. 5. What is the best first step before you start fixing an unfamiliar misbehaving server?

    Evidence and recent changes narrow the hypothesis; a reboot may destroy both.

Summary

  • Practise on disposable VMs and write your plan before you look at solutions.
  • Name resolution, firewalls, SSH permissions, SELinux labels, cron environment, deleted-open files and I/O wait account for a large share of real incidents.
  • For each problem, find the layer (link, address, route, name, firewall, service, permission, MAC) and test it with a second tool.
  • Make fixes permanent in configuration, monitor them and capture them as code.

You have reached the end of this part of the track. Return to the Linux System Administration overview to revisit any chapter.

Next: Linux System Administration