Five exercises covering systemd service management, custom unit file creation, journalctl log investigation, cron job scheduling, and daemon persistence auditing — the skills every Linux administrator uses daily.
systemctl list-units --type=service --state=runningsystemctl list-units --type=service --allsystemctl --failed --type=servicesystemctl status sshd (or ssh on some distros)systemctl is-enabled sshdsystemctl is-active sshdsystemctl cat sshdsystemctl list-dependencies sshdsudo systemctl daemon-reloadsystemctl is-enabled sshd && systemctl is-active sshd. The enable --now flag combines both operations atomically.echo '#!/bin/bash' > /usr/local/bin/healthcheck.sh && echo 'while true; do echo "$(date): OK" >> /var/log/healthcheck.log; sleep 60; done' >> /usr/local/bin/healthcheck.shchmod +x /usr/local/bin/healthcheck.shsudo nano /etc/systemd/system/healthcheck.servicesudo systemctl daemon-reloadsudo systemctl start healthchecksystemctl status healthchecksudo systemctl enable healthchecktail -5 /var/log/healthcheck.logsudo systemctl kill healthcheck — then check status again to see it restartsudo systemctl stop healthcheck && sudo systemctl disable healthcheck. Then remove the unit file: sudo rm /etc/systemd/system/healthcheck.service && sudo systemctl daemon-reload. Always clean up test services from production-adjacent systems.Type= directive is subtle but important: simple (default, process stays in foreground), forking (process forks a child daemon and exits), oneshot (runs once and exits), notify (service sends a ready notification via sd_notify). Getting Type= wrong causes systemd to mistrack the service state.journalctl -b -e (current boot, end of log)journalctl -b -1 (last reboot cycle)journalctl --list-bootsjournalctl -u sshd.servicejournalctl -u sshd.service -f (Ctrl+C to exit)journalctl -p err..emergjournalctl --since "2025-01-15 09:00" --until "2025-01-15 10:00"journalctl --since "30 minutes ago"journalctl -u sshd -n 5 -o json-prettyjournalctl --disk-usage-o json output exposes all metadata fields. The boot ID (_BOOT_ID field) lets you correlate events across services to a specific boot session. Use journalctl -F _SYSTEMD_UNIT to see all unit names that have ever logged — including ones no longer installed.crontab -e — this opens the user's personal cron tablesudo crontab -ecrontab -lls /etc/cron.{daily,weekly,monthly,hourly}* * * * * echo "$(date): cron test" >> /tmp/cron-test.logtail -5 /tmp/cron-test.loggrep CRON /var/log/syslog | tail -20 or journalctl -u cron.service --since today$PATH is not your interactive shell path. Always use absolute paths in cron scripts (/usr/bin/python3 not python3). Always redirect both stdout and stderr (>> logfile 2>&1) or you will never see errors — they silently disappear or get emailed to root. The /etc/cron.allow and /etc/cron.deny files control which users can create cron jobs. On a hardened system, restrict cron access to authorized users only. Also note: systemd timers are increasingly replacing cron — they integrate with journalctl, support dependencies, and have better failure handling.systemctl list-unit-files --type=service --state=enabledls -la ~/.config/systemd/user/ 2>/dev/null and find /home -name "*.service" 2>/dev/nullls -lt /etc/systemd/system/ | head -20 (recently modified files are suspicious)for u in $(cut -d: -f1 /etc/passwd); do echo "=== $u ==="; crontab -u "$u" -l 2>/dev/null; donels -la /etc/cron.d/ /etc/cron.daily/ /etc/cron.weekly/ /etc/cron.monthly/ /etc/cron.hourly/cat /etc/crontabcat /etc/rc.local 2>/dev/nullfind /etc/systemd /lib/systemd /usr/lib/systemd -name "*.service" -newer /boot -ls 2>/dev/null | head -15systemctl list-unit-files --state=enabled > ~/enabled-services-audit.txtdbus-daemon-helper.service; (2) Add a cronjob to root's crontab or /etc/cron.d/ that re-downloads the payload; (3) Add an entry to /etc/rc.local (legacy but still works); (4) Hijack an existing service's ExecStart path by replacing the binary. The red flags are: service names that mimic legitimate daemons, ExecStart pointing to /tmp or /dev/shm, services running as root with no legitimate description, and unit files with no corresponding package in the package manager.