Debian Cheat Sheet
Common commands for Debian Server Administration.
Getting Help
| Command / Resource | Description |
|---|
man page or man bash | Read the help page for every command and many configuration files. Also available online: https://www.manpages.debian.org/ |
command [--help, -h] | Brief help for most commands. |
/usr/share/doc/package-name/ | Find all documentation here; the optional file README.Debian contains Debian-specific notes. |
| Web documentation | Reference, manuals, FAQs, HOWTOs, etc. |
| Mailing lists | The community is always helpful; search for users. Or use other channels like IRC: https://www.debian.org/support/ |
| The Wiki | Contains all kinds of useful information. |
⭐ man -k keyword / apropos keyword | Search man pages by keyword. |
⭐ info command | Read GNU info documentation. |
⭐ whatis command | One-line description of a command. |
⭐ type command / which command | Show how a command resolves / where it lives. |
⭐ tldr command | Simplified community examples (needs tldr package). |
Installation
| Resource | Description |
|---|
| Installer | All information about the installer. |
| CD images | Download installation images. |
boot: expert | E.g. to set up the network without DHCP or to adapt the bootloader installation. |
| Live image | Contains the user-friendly Calamares installer. |
⭐ sha256sum -c SHA256SUMS | Verify the integrity of a downloaded ISO. |
⭐ sudo dd if=debian.iso of=/dev/sdX bs=4M status=progress conv=fsync | Write an ISO to a USB drive (double-check /dev/sdX!). |
Configuration
| Command / Path | Description |
|---|
/etc/ | All system configuration files are under this directory. |
editor files | Default text editor. May be nano, emacs, vi, joe. |
| CUPS | Browser interface to the printing system (http://hostname:631). |
dpkg-reconfigure package-name | Reconfigure a package, e.g. keyboard-configuration (keyboard), locales (localization). |
update-alternatives options | Manage command alternatives. |
update-grub | Run after changing /etc/default/grub. |
⭐ sudo update-alternatives --config editor | Interactively choose the default editor. |
⭐ sudo visudo | Safely edit /etc/sudoers. |
⭐ sudo timedatectl set-timezone America/Santiago | Set the system time zone. |
⭐ timedatectl | Show date, time, and NTP sync status. |
⭐ sudo hostnamectl set-hostname NAME | Set the machine hostname. |
⭐ sudo dpkg-reconfigure tzdata | Reconfigure time zone interactively. |
⭐ locale / sudo dpkg-reconfigure locales | Show / configure system locales. |
⭐ /etc/apt/sources.list and /etc/apt/sources.list.d/ | APT repository definitions (Trixie also supports deb822 .sources files). |
⭐ /etc/fstab | Filesystems mounted at boot. |
⭐ /etc/hosts | Static hostname-to-IP mappings. |
Daemons and System
| Command / Path | Description |
|---|
systemctl restart name.service | Restart a service / system daemon. |
systemctl stop name.service | Stop a service / system daemon. |
systemctl start name.service | Start a service / system daemon. |
systemctl halt | Halts the system. |
systemctl reboot | Reboots the system. |
systemctl poweroff | Shuts down the system. |
systemctl suspend | Suspends the system. |
systemctl hibernate | Hibernates the system. |
/var/log/ | All log files are under this directory. |
/etc/default/ | Default values for many daemons and services. |
⭐ systemctl status name.service | Show service status and recent log lines. |
⭐ systemctl enable name.service | Start a service at boot. |
⭐ systemctl enable --now name.service | Enable at boot and start immediately. |
⭐ systemctl disable name.service | Do not start a service at boot. |
⭐ systemctl reload name.service | Reload configuration without full restart. |
⭐ systemctl is-active name.service | Check if a service is running. |
⭐ systemctl list-units --type=service | List loaded services. |
⭐ systemctl list-unit-files --state=enabled | List services enabled at boot. |
⭐ systemctl --failed | List failed units. |
⭐ systemctl daemon-reload | Reload systemd after editing unit files. |
⭐ systemctl edit name.service | Create a drop-in override for a unit. |
⭐ journalctl -u name.service -f | Follow logs for a service. |
⭐ journalctl -xe | Show recent logs with explanations. |
⭐ journalctl -b | Logs since the current boot. |
⭐ journalctl -p err -b | Only errors since boot. |
⭐ journalctl --vacuum-time=7d | Trim journal logs older than 7 days. |
⭐ systemd-analyze blame | Show which units slow down boot. |
⭐ uptime / uname -a / hostnamectl | System uptime / kernel info / host info. |
⭐ lsb_release -a / cat /etc/os-release | Show Debian version. |
⭐ crontab -e / crontab -l | Edit / list the user’s cron jobs. |
⭐ systemctl list-timers | List systemd timers. |
Important Shell Commands
Files and directories
| Command | Description |
|---|
cat files | Print files to screen. |
cd directory | Change to directory. |
cp files dest | Copy files and directories. |
echo string | Echo string to screen. |
gzip, bzip2, xz [-d] files | Compress, uncompress files. |
pager files | Show contents of files. |
ls [files] | List files. |
mkdir directory-names | Create directories. |
mv file1 file2 | Move, rename files. |
rm files | Remove files. |
rmdir dirs | Remove empty directories. |
tar [c][x][t][z][j][J] -f file.tar [files] | Create (c), extract (x), list table of (t) archive file; z for .gz, j for .bz2, J for .xz. |
find directories expressions | Find files, like -name name or -size +1000, etc. |
grep search-string files | Find search-string in files. |
ln -s file link | Create a symbolic link to a file. |
Processes and users
| Command | Description |
|---|
ps [options] | Show current processes. |
kill [-9] PID | Send signal to a process (e.g. terminate it). Use ps for the PID. |
su - [username] | Become another user, e.g. root. |
sudo command | Execute a command as root as a normal user, see /etc/sudoers. |
Redirection and pipes
| Command | Description |
|---|
command > file | Overwrite file with output of command. |
command >> file | Append output of command to file. |
cmd1 | cmd2 | Use output of command 1 as input of command 2. |
command < file | Use file as input for command. |
⭐ Additional shell commands
| Command | Description |
|---|
ls -lah | Long listing, hidden files, human-readable sizes. |
tree -L 2 | Directory tree, 2 levels deep (needs tree). |
cp -a src dest | Copy preserving permissions, timestamps, links. |
rm -rf dir | Remove a directory recursively (dangerous, no undo). |
touch file | Create an empty file / update timestamp. |
head -n 20 file / tail -n 20 file | First / last lines of a file. |
tail -f file | Follow a file as it grows (logs). |
less file | Scroll through a file (q to quit, / to search). |
wc -l file | Count lines. |
sort file | uniq -c | Sort and count duplicates. |
cut -d: -f1 /etc/passwd | Extract a column by delimiter. |
sed -i 's/old/new/g' file | In-place search and replace. |
awk '{print $1}' file | Print first column. |
grep -rin "text" . | Recursive, case-insensitive search with line numbers. |
find . -name "*.log" -mtime +7 | Find .log files older than 7 days. |
find . -type f -size +100M | Find files larger than 100 MB. |
xargs | Build commands from stdin, e.g. find . -name "*.tmp" | xargs rm. |
tar -czvf out.tar.gz dir/ | Create a gzip-compressed archive. |
tar -xzvf in.tar.gz -C /dest | Extract a gzip archive to a destination. |
zip -r out.zip dir/ / unzip file.zip | Create / extract zip files. |
chmod 755 file / chmod +x script.sh | Change permissions. |
chown user:group file | Change owner and group. |
chown -R user:group dir | Change ownership recursively. |
umask | Show default permission mask. |
stat file | Detailed file information. |
file name | Detect file type. |
diff -u a b | Compare two files. |
alias ll='ls -lah' | Create a shell alias (persist in ~/.bashrc). |
history / Ctrl+R | Command history / reverse search. |
!! | Repeat last command (e.g. sudo !!). |
source ~/.bashrc | Reload shell configuration. |
export VAR=value | Set an environment variable. |
env / printenv | List environment variables. |
watch -n 2 command | Re-run a command every 2 seconds. |
time command | Measure how long a command takes. |
tmux / screen | Persistent terminal sessions (need packages). |
⭐ Users and groups
| Command | Description |
|---|
whoami / id | Current user / UID, GID, and groups. |
sudo adduser name | Create a user (interactive, Debian-friendly). |
sudo usermod -aG sudo name | Add a user to the sudo group. |
sudo deluser --remove-home name | Delete a user and their home directory. |
sudo passwd name | Change a user’s password. |
groups name | Show a user’s groups. |
last | Show recent logins. |
w / who | Who is logged in and what they are doing. |
⭐ Processes and resources
| Command | Description |
|---|
top / htop | Interactive process viewer (htop needs package). |
ps aux | List all processes. |
ps aux | grep name | Find a process by name. |
pgrep -a name | Find PIDs by name. |
pkill name | Kill processes by name. |
killall name | Kill all processes with that name. |
nice -n 10 cmd / renice -n 5 -p PID | Start with / change priority. |
bg / fg / jobs | Manage background jobs. |
command & | Run a command in background. |
nohup command & | Keep running after logout. |
free -h | Memory usage. |
vmstat 1 | Live virtual memory/CPU stats. |
lsof -i :80 | Which process uses port 80. |
dmesg -T | tail | Recent kernel messages with human-readable time. |
⭐ Disk and filesystems
| Command | Description |
|---|
df -h | Free disk space per filesystem. |
du -sh * | Size of each item in the current directory. |
du -h --max-depth=1 / | sort -h | Largest top-level directories. |
ncdu | Interactive disk usage browser (needs package). |
lsblk | List block devices. |
lsblk -f | List block devices with filesystems and UUIDs. |
blkid | Show UUIDs and filesystem types. |
sudo fdisk -l | List disk partitions. |
sudo mount /dev/sdX1 /mnt / sudo umount /mnt | Mount / unmount a partition. |
sudo mount -a | Mount everything in /etc/fstab (test your edits). |
sudo fsck /dev/sdX1 | Check a filesystem (unmounted!). |
sudo mkfs.ext4 /dev/sdX1 | Format as ext4 (destroys data). |
sudo smartctl -a /dev/sda | Disk SMART health (needs smartmontools). |
⭐ Hardware info
| Command | Description |
|---|
lscpu | CPU information. |
lspci / lsusb | PCI / USB devices. |
sudo lshw -short | Hardware summary. |
sudo dmidecode -t system | BIOS/system information. |
sensors | Temperatures (needs lm-sensors). |
nvidia-smi | NVIDIA GPU status (with proprietary drivers). |
APT
| Command | Description |
|---|
apt update | Update package listings from repositories listed in /etc/apt/sources.list. Required whenever that file or the contents of the repositories change. |
apt search search-string | Search packages and descriptions for the string. |
apt list -a package-name | Show versions and archive areas of available packages. |
apt show -a package-name | Show package information including description. |
apt install package-names | Install packages from repositories with all dependencies. |
apt upgrade | Install newest versions of all packages currently installed. |
apt full-upgrade | Like apt upgrade, but with advanced conflict resolution. |
apt remove package-names | Remove packages. |
apt autoremove | Remove packages that no other packages depend on. |
apt depends package-name | List all packages needed by the one given. |
apt rdepends package-name | List all packages that need the one given. |
apt-file update | Update content listings from package repositories, see apt update. |
apt-file search file-name | Search packages for a file. |
apt-file list package-name | List contents of a package. |
aptitude | Console interface to APT (needs aptitude). |
synaptic | GUI interface to APT (needs synaptic). |
⭐ Additional APT commands
| Command | Description |
|---|
sudo apt update && sudo apt upgrade -y | Typical full refresh and upgrade. |
sudo apt full-upgrade | Upgrade handling changed dependencies. |
sudo apt purge package | Remove a package and its configuration files. |
sudo apt autoremove --purge | Remove unused packages and their configs. |
sudo apt clean | Delete all cached .deb files. |
sudo apt autoclean | Delete only obsolete cached .deb files. |
sudo apt install ./file.deb | Install a local .deb resolving dependencies. |
sudo apt install --reinstall package | Reinstall a package. |
sudo apt install package=version | Install a specific version. |
sudo apt install -t trixie-backports package | Install from backports. |
sudo apt --fix-broken install | Repair broken dependencies. |
apt list --installed | List installed packages. |
apt list --upgradable | List packages with updates available. |
apt policy package | Show candidate version and pinning/priorities. |
apt-mark hold package / apt-mark unhold package | Prevent / allow upgrades of a package. |
apt-mark showhold | List held packages. |
apt-mark showmanual | List manually installed packages. |
sudo apt build-dep package | Install build dependencies (needs deb-src). |
apt source package | Download package source. |
sudo apt modernize-sources | Convert legacy sources.list to deb822 format. |
sudo apt-get dist-upgrade | Legacy equivalent of full-upgrade. |
needrestart | Show services/processes needing restart after upgrades (needs package). |
sudo unattended-upgrades --dry-run | Test automatic security upgrades (needs unattended-upgrades). |
sudo add-apt-repository | Not shipped by default on Debian; edit /etc/apt/sources.list.d/ instead. |
⭐ Third-party repository (modern way, with keyrings)
sudo install -d -m 0755 /etc/apt/keyrings
curl -fsSL https://example.com/key.gpg | sudo gpg --dearmor -o /etc/apt/keyrings/example.gpg
echo "deb [signed-by=/etc/apt/keyrings/example.gpg] https://example.com/apt stable main" \
| sudo tee /etc/apt/sources.list.d/example.list
sudo apt update
Dpkg
| Command | Description |
|---|
dpkg -l [names] | List packages. |
dpkg -I pkg.deb | Show package information. |
dpkg -c pkg.deb | List contents of a package file. |
dpkg -S filename | Show which package a file belongs to. |
dpkg -i pkg.deb | Install package files. |
dpkg -V [package-names] | Audit checksums of installed packages. |
dpkg-divert [options] file | Override a package’s version of a file. |
dpkg --compare-versions v1 gt v2 | Compare version numbers; view results with echo $?. |
dpkg-query -W --showformat=format | Query installed packages, format e.g. '${Package} ${Version} ${Installed-Size}\n' |
dpkg --get-selections > file | Write package selections to file. |
dpkg --set-selections < file | Set package selections from file. |
⭐ Additional dpkg commands
| Command | Description |
|---|
dpkg -L package | List files installed by a package. |
dpkg -s package | Show status of an installed package. |
dpkg -r package | Remove a package (keep config). |
dpkg -P package | Purge a package (remove config too). |
sudo dpkg --configure -a | Finish configuring interrupted installations. |
dpkg --print-architecture | Show the native architecture. |
dpkg --print-foreign-architectures | Show enabled foreign architectures. |
sudo dpkg --add-architecture i386 | Enable multiarch (e.g. i386). |
dpkg -l | grep ^ii | Only fully installed packages. |
dpkg -l | grep ^rc | Removed packages with leftover config. |
sudo dpkg -P $(dpkg -l | awk '/^rc/{print $2}') | Purge leftover configs of removed packages. |
The Network
| Command / Path | Description |
|---|
/etc/network/interfaces | Interface configuration (if not controlled via NetworkManager). |
if[up][down] device | Start, stop network interfaces according to the file above. |
ip | Show and manipulate network interfaces and routing (needs iproute2). |
ssh -X user@host | Login at another machine (with X11 forwarding). |
scp files user@host:path | Copy files to another machine (and vice versa). |
⭐ Additional networking commands
| Command | Description |
|---|
ip a / ip addr | Show IP addresses. |
ip -br a | Brief address overview. |
ip link | Show network interfaces and state. |
sudo ip link set eth0 up / down | Bring an interface up / down. |
ip route | Show routing table. |
ip route get 1.1.1.1 | Show which route/interface reaches a host. |
ss -tulpn | Listening TCP/UDP sockets with owning processes. |
ss -tn | Established TCP connections. |
ping -c 4 host | Test connectivity. |
traceroute host / mtr host | Trace the route to a host (need packages). |
dig domain / nslookup domain | DNS lookups (need dnsutils/bind9-dnsutils). |
dig +short domain | Only the answer. |
host domain | Simple DNS lookup. |
resolvectl status | DNS resolver status (systemd-resolved). |
curl -I https://example.com | Fetch HTTP headers only. |
curl -fsSL URL -o file | Download a file quietly, failing on errors. |
wget URL / wget -c URL | Download / resume download. |
nmcli device status | NetworkManager device status. |
nmcli connection show | List NetworkManager connections. |
nmcli device wifi list / nmcli device wifi connect SSID password PASS | List / connect to Wi-Fi. |
nmtui | Text UI for NetworkManager. |
sudo systemctl restart networking | Restart ifupdown networking. |
sudo systemctl restart NetworkManager | Restart NetworkManager. |
hostname -I | Show all local IP addresses. |
curl ifconfig.me | Show public IP address. |
nc -zv host 22 | Test whether a TCP port is open (needs netcat). |
nmap host | Port scan (needs nmap; only scan hosts you own/are authorized to). |
sudo tcpdump -i eth0 port 80 | Capture packets (needs tcpdump). |
⭐ SSH and file transfer
| Command | Description |
|---|
ssh user@host | Connect to a remote machine. |
ssh -p 2222 user@host | Connect using a non-default port. |
ssh -i ~/.ssh/key user@host | Connect with a specific key. |
ssh-keygen -t ed25519 -C "comment" | Generate an Ed25519 key pair. |
ssh-copy-id user@host | Install your public key on a remote host. |
ssh -L 8080:localhost:80 user@host | Local port forwarding (tunnel). |
ssh -D 1080 user@host | SOCKS proxy through SSH. |
ssh -J jump@host user@target | Connect through a jump host. |
scp -r dir user@host:/path | Copy a directory recursively. |
scp -P 2222 file user@host:/path | Copy using a non-default port. |
rsync -avzP src/ user@host:/dest/ | Efficient sync with progress and resume. |
rsync -avz --delete src/ dest/ | Mirror, deleting extra files at the destination. |
sftp user@host | Interactive file transfer. |
~/.ssh/config | Per-host SSH settings (Host, HostName, User, Port, IdentityFile). |
⭐ Firewall
| Command | Description |
|---|
sudo ufw status verbose | Show firewall status (needs ufw). |
sudo ufw allow 22/tcp | Allow SSH. |
sudo ufw allow from 192.168.1.0/24 to any port 5432 | Allow a subnet to a port. |
sudo ufw allow from 192.168.1.0 to any port 5432 | Allow a specific ip to a port. |
sudo ufw allow from 192.168.1.0 to any port 5432 proto tcp | Allow a specific ip to a port with only tcp protocol. |
sudo ufw deny 23 | Block a port. |
sudo ufw enable / disable | Enable / disable the firewall. |
sudo ufw delete allow 22/tcp | Remove a rule. |
sudo nft list ruleset | Show nftables rules (Debian default backend). |
sudo systemctl status fail2ban | Check brute-force protection (needs fail2ban). |
Kernel and boot
| Command | Description |
|---|
uname -r | Running kernel version. |
dpkg -l 'linux-image*' | grep ^ii | Installed kernels. |
sudo update-initramfs -u | Rebuild the initramfs. |
sudo update-grub | Regenerate GRUB configuration. |
lsmod | Loaded kernel modules. |
sudo modprobe module | Load a kernel module. |
sudo sysctl -a | grep keyword | Search kernel parameters. |
sudo sysctl -p | Reload /etc/sysctl.conf. |
Upgrading Debian to a new release (e.g. 12 → 13)
# 1. Fully update the current system first
sudo apt update && sudo apt full-upgrade
# 2. Back up, then change codenames in /etc/apt/sources.list(.d/)
sudo sed -i 's/bookworm/trixie/g' /etc/apt/sources.list
# 3. Upgrade in two steps
sudo apt update
sudo apt upgrade --without-new-pkgs
sudo apt full-upgrade
# 4. Clean up and reboot
sudo apt autoremove --purge
sudo reboot
Always read the official release notes before a major upgrade: https://www.debian.org/releases/stable/releasenotes
Handy one-liners
# Show the 10 biggest files/directories under the current path
du -ah . 2>/dev/null | sort -rh | head -n 10
# Show the 10 processes using the most memory
ps aux --sort=-%mem | head -n 11
# Find which process is using a port
sudo ss -tulpn | grep :8080
# Count files in a directory recursively
find . -type f | wc -l
# Update everything and clean up in one go
sudo apt update && sudo apt full-upgrade -y && sudo apt autoremove --purge -y && sudo apt clean