guest@websec ~ % man hier
Ubuntu Server Folders
Every file on the server lives in one tree that starts at /. Click a folder on the left (or use ← →) to see what's inside on a real-looking server, what it's for, and whether you should touch it.
Your code and files live in
/home or /srv, server settings live in /etc, live app data and logs live in /var (watch disk usage here!), and OS packages own /usr — never hand-edit /usr.- yours
- put your own files and apps here
- config
- settings: edit with sudo, carefully, and keep a backup
- data
- apps write here: read it and back it up, don't hand-edit
- system
- owned by apt: never add, edit or delete files
- virtual
- made up by the kernel on the fly, not on disk
- temp
- scratch space that gets wiped
This folder
Commands shown
Where does … live?
The question you'll actually ask. Paths from lesson s01 included.
| thing | path |
|---|---|
| SSH server settings | /etc/ssh/sshd_config.d/*.conf |
| who may log in as ubuntu | /home/ubuntu/.ssh/authorized_keys |
| sudo rules | /etc/sudoers.d/ |
| firewall rules | /etc/ufw/user.rules (change them with ufw, not by hand) |
| apt sources and keys | /etc/apt/sources.list.d/, /etc/apt/keyrings/ |
| your systemd services | /etc/systemd/system/myapp.service |
| services installed by packages | /usr/lib/systemd/system/ (override with systemctl edit) |
| logs | /var/log/ and journalctl (stored in /var/log/journal/) |
| Docker images, containers, volumes | /var/lib/docker/ |
| a container's log file | /var/lib/docker/containers/<id>/<id>-json.log |
| Docker daemon settings | /etc/docker/daemon.json |
| Postgres data (apt install) | /var/lib/postgresql/16/main/, config in /etc/postgresql/16/main/ |
| nginx sites | /etc/nginx/sites-available/ + symlink in sites-enabled/ |
| Let's Encrypt certificates | /etc/letsencrypt/live/<domain>/ |
| your crontab | crontab -e (stored in /var/spool/cron/crontabs/ubuntu) |
| Node versions (nvm) | ~/.nvm/versions/node/ |
| Ruby versions (rvm) | ~/.rvm/rubies/ |
| Python versions (pyenv) | ~/.pyenv/versions/ |
| swap file | /swapfile |
| your app's code | /srv/myapp or /home/ubuntu/apps/myapp: pick one and stick to it |
| a binary you downloaded | /usr/local/bin/ |
Disk full? Find what's big
| command | what it tells you |
|---|---|
df -h | free space per disk. Ignore the /dev/loop* lines (snaps). |
sudo du -xh --max-depth=1 / | sort -h | size of each top-level folder. -x stays on one disk, so it skips /proc. |
sudo du -sh /var/* | sort -h | usually the answer: logs, Docker or apt cache |
docker system df | space used by images, containers, volumes, build cache |
journalctl --disk-usage | size of the systemd journal. Shrink: sudo journalctl --vacuum-size=200M |
sudo apt clean && sudo apt autoremove | drop downloaded .deb files and old kernels |
sudo apt install ncdu && sudo ncdu -x / | interactive browser of what uses the space |
What to back up
/etc: all your configuration. Small, and painful to rebuild by memory.etckeeperputs it in git automatically./homeand/srv(or wherever your apps live): code,.envfiles, uploads.- Databases: a dump (
pg_dump,mysqldump), not a copy of/var/lib/postgresqlwhile it's running. - Docker volumes in
/var/lib/docker/volumes/: stop the container or use the app's own dump tool first. /var/spool/cron/crontabs: everyone's crontabs.
Not worth backing up: /usr, /boot, /var/cache, /tmp, /proc, /sys, /dev, /run. A reinstall brings those back.