Linux commands
Services and logs#
A service is a program that runs in the background and starts by itself at boot (SSH, Samba, the AI model, Fail2ban…). systemctl controls them and journalctl shows what they wrote.
systemctl#
| Command | Does |
|---|---|
systemctl is-active ssh |
One word: active, inactive or failed |
systemctl status ssh --no-pager |
State, start time, last log lines |
systemctl --failed |
Everything that failed. Should be empty |
sudo systemctl start NAME |
Start now |
sudo systemctl stop NAME |
Stop now |
sudo systemctl restart NAME |
Stop and start |
sudo systemctl reload NAME |
Re-read settings without stopping (SSH, Samba) |
sudo systemctl enable --now NAME |
Start now and at every boot |
sudo systemctl disable --now NAME |
Stop now and don't start at boot |
systemctl is-enabled NAME |
Will it start at boot? |
systemctl cat NAME |
Show its service file |
sudo systemctl daemon-reload |
Always run this after editing a .service file |
systemctl list-timers |
Scheduled jobs (updates etc.) and when they run next |
The services on this server:
| Name | What |
|---|---|
ssh |
Remote login |
ufw |
Firewall |
avahi-daemon |
The homeserver.local name |
tailscaled |
Tailscale |
smbd |
File sharing |
fail2ban |
Bans password-guessers |
cockpit.socket |
Dashboard |
llama-model |
AI model |
ai-egress-guard |
Keeps the AI offline (shows active even though it's not "running"; that's normal) |
User services (yours, not the system's)#
The agent system runs as your user, so add --user and leave out sudo:
systemctl --user status aisystem
systemctl --user restart aisystem
journalctl --user -u aisystem -n 50
loginctl show-user $USER -p Linger # Linger=yes = keeps running after logout
journalctl: read the logs#
| Command | Shows |
|---|---|
sudo journalctl -u ssh -n 50 |
Last 50 lines from one service |
sudo journalctl -u llama-model -f |
Follow live (Ctrl+C stops) |
sudo journalctl -b |
Everything since the last boot |
sudo journalctl -b -1 |
The previous boot (what happened before a crash) |
sudo journalctl -p err -b |
Only errors since boot |
sudo journalctl --since "1 hour ago" |
Recent lines |
sudo journalctl --since today -u fail2ban |
Combine |
journalctl --disk-usage |
How much space logs use |
Other logs in files:
| File | What |
|---|---|
/var/log/unattended-upgrades/unattended-upgrades.log |
Automatic updates |
/var/log/apt/history.log |
Everything installed or removed |
/var/log/nightly-backup.log |
Your backup job (Chapter 17) |
Processes#
| Command | Does |
|---|---|
htop |
Live list; F9 sends a stop signal to the selected one |
ps aux | grep llama |
Find a running program and its number (PID) |
kill PID |
Ask a program to stop |
kill -9 PID |
Force it (last resort) |
For services, use systemctl stop instead of kill. Otherwise systemd simply restarts them.