Tips & Tricks
Expert tips, hidden features, and productivity-enhancing tricks to make the most of your Debian system.
Speed Up Your System
Optimize Debian for better performance and responsiveness
Use ZRAM for Swap Compression
Instead of a traditional swap partition, use ZRAM to compress data in memory. This dramatically improves performance on systems with limited RAM.
$ sudo apt install zram-tools $ sudo systemctl enable --now zramswap $ zramctl # Verify it's working
Enable TRIM for SSDs
Regularly running TRIM on SSDs maintains their performance over time. Set up a weekly fstrim timer:
$ sudo systemctl enable --now fstrim.timer $ systemctl status fstrim.timer
Use a Faster DNS
Replace your ISP's DNS with faster, more reliable options like Cloudflare (1.1.1.1) or Google (8.8.8.8):
# Edit resolv.conf or use systemd-resolved $ echo "nameserver 1.1.1.1" | sudo tee /etc/resolv.conf $ echo "nameserver 8.8.8.8" | sudo tee -a /etc/resolv.conf # Or install DNS-over-HTTPS with systemd-resolved $ sudo systemd-resolve --set-dns 1.1.1.1 8.8.8.8
Reduce Swap Usage (Swappiness)
Lower the swappiness value to prefer RAM over swap, reducing disk I/O:
# Check current value (default is 60) $ cat /proc/sys/vm/swappiness # Set to 10 (prefer RAM over swap) $ echo "vm.swappiness=10" | sudo tee /etc/sysctl.d/99-swappiness.conf $ sudo sysctl --system
Use a Lightweight Desktop
If your system feels slow, switch to a lighter desktop environment:
# Install XFCE (lightweight, feature-rich) $ sudo apt install task-xfce-desktop # Or LXQt (even lighter) $ sudo apt install task-lxqt-desktop # Or MATE (traditional, moderate weight) $ sudo apt install task-mate-desktop
Clean Up Regularly
Set up automatic cleanup to keep your system running smoothly:
# Create a cleanup script $ cat >~/cleanup.sh <<'EOF' #!/bin/bash sudo apt clean sudo apt autoremove --purge -y sudo journalctl --vacuum-time=7d rm -rf ~/.cache/thumbnails/* echo "Cleanup complete!" EOF $ chmod +x ~/cleanup.sh # Run weekly via cron $ crontab -e # Add: 0 3 * * 0 ~/cleanup.sh
Hardening Your System
Essential security measures every Debian user should implement
Configure a Firewall
Always run a firewall. UFW (Uncomplicated Firewall) is the easiest to configure:
$ sudo apt install ufw $ sudo ufw default deny incoming $ sudo ufw default allow outgoing $ sudo ufw allow 22/tcp # SSH $ sudo ufw allow 80/tcp # HTTP $ sudo ufw allow 443/tcp # HTTPS $ sudo ufw enable
SSH Hardening
Secure your SSH server against brute-force attacks:
# Edit SSH config $ sudo nano /etc/ssh/sshd_config # Recommended settings: Port 2222 # Non-standard port PermitRootLogin no # Disable root login PasswordAuthentication no # Use keys only MaxAuthTries 3 # Limit login attempts ClientAliveInterval 300 # Timeout idle sessions $ sudo systemctl restart ssh # Install fail2ban for brute-force protection $ sudo apt install fail2ban
Enable Automatic Security Updates
Keep your system patched automatically:
$ sudo apt install unattended-upgrades $ sudo dpkg-reconfigure unattended-upgrades # Configure in /etc/apt/apt.conf.d/50unattended-upgrades # Enable automatic reboot if needed $ echo "Unattended-Upgrade::Automatic-Reboot \"true\";" | sudo tee /etc/apt/apt.conf.d/auto-reboot
Full Disk Encryption
If you didn't encrypt during installation, you can still protect sensitive data:
# Encrypt a specific partition/drive $ sudo cryptsetup luksFormat /dev/sdX1 $ sudo cryptsetup luksOpen /dev/sdX1 encrypted $ sudo mkfs.ext4 /dev/mapper/encrypted $ sudo mount /dev/mapper/encrypted /mnt/secure
Power User Tips
Advanced tricks to boost your productivity and customize your Debian experience
Customize Your Shell (Bash/Zsh)
Enhance your terminal experience with aliases, functions, and Oh My Zsh:
# Useful aliases for ~/.bashrc alias update='sudo apt update && sudo apt full-upgrade -y' alias clean='sudo apt autoremove --purge -y && sudo apt autoclean' alias ll='ls -la --color=auto' alias ..='cd ..' alias ....='cd ../..' # Install Oh My Zsh for a better shell $ sudo apt install zsh $ sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" # Install powerlevel10k theme $ git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/themes/powerlevel10k
Use tmux for Terminal Multiplexing
tmux lets you run multiple terminal sessions in one window and detach/reattach:
$ sudo apt install tmux # Basic tmux commands (prefix is Ctrl+b) # Ctrl+b % → Split vertically # Ctrl+b " → Split horizontally # Ctrl+b ←→ → Navigate between panes # Ctrl+b c → Create new window # Ctrl+b d → Detach from session $ tmux new -s myproject # Named session $ tmux attach -t myproject # Reattach
Set Up Snapshots with Timeshift
Create system snapshots for easy rollback in case something breaks:
$ sudo apt install timeshift # Create a snapshot $ sudo timeshift --create --comments "Before upgrade" # List snapshots $ sudo timeshift --list # Restore a snapshot (use with caution!) $ sudo timeshift --restore --snapshot "2024-01-15_12-00-00"
Use debsums to Verify Package Integrity
Check if any system files have been modified or tampered with:
$ sudo apt install debsums # Check all packages $ sudo debsums -c # Check specific package $ sudo debsums nginx # Check after a security update $ sudo debsums --all --changed
Pin APT Repositories
Control which version of a package gets installed by pinning specific repositories:
# Create a pin preference file $ cat | sudo tee /etc/apt/preferences.d/vim-pin <<'EOF' Package: vim Pin: release a=stable Pin-Priority: 900 EOF # Check pin status $ apt-cache policy vim # Pin a specific version $ sudo apt install vim=2:8.2.3995-1
Use Alias for Sudo Commands
Save time with smart aliases that combine common operations:
# Add to ~/.bashrc alias supdate='sudo apt update && sudo apt list --upgradable' alias supgrade='sudo apt update && sudo apt full-upgrade -y' alias sclean='sudo apt autoremove --purge -y && sudo apt clean' alias sgrep='sudo grep -r --include="*.conf"' alias sysinfo='neofetch || screenfetch' # Install neofetch for system info $ sudo apt install neofetch
Manage Services with Systemctl Aliases
Create quick functions to manage common services without typing full commands:
# Add to ~/.bashrc svc() { sudo systemctl "$@" } # Usage examples: $ svc status nginx $ svc restart ssh $ svc enable --now fail2ban $ svc list-units --failed
Use ripgrep for Fast Searching
ripgrep is a blazingly fast alternative to grep for searching through files:
$ sudo apt install ripgrep # Search for a pattern in all files $ rg "error" /var/log/ # Search only in specific file types $ rg "TODO" -t py src/ # Search with context lines $ rg "config" -C 3 /etc/nginx/ # Count matches $ rg -c "warning" /var/log/syslog
Backup & Recovery
Protect your data with reliable backup strategies and monitoring tools
Monitor Disk Space with ncdu
ncdu is an interactive disk usage analyzer that helps you find large files quickly:
$ sudo apt install ncdu # Analyze a directory $ ncdu /home # Analyze entire system (as root) $ sudo ncdu / # Exclude certain directories $ ncdu -x / # Stay on same filesystem # Quick one-liner check $ df -h /
Set Up Encrypted Backups with Restic
Restic provides deduplicated, encrypted backups to any storage backend:
$ sudo apt install restic # Initialize a backup repository $ export RESTIC_REPOSITORY=/mnt/backup/debian $ export RESTIC_PASSWORD="your-strong-password" $ restic init # Backup your home directory $ restic backup /home --tag home # List backups $ restic snapshots # Restore a specific snapshot $ restic restore latest --target /mnt/restore
Check Disk Health with smartctl
Monitor your drive's health using S.M.A.R.T. data to predict failures:
$ sudo apt install smartmontools # Quick health check $ sudo smartctl -H /dev/sda # Full S.M.A.R.T. data $ sudo smartctl -a /dev/sda # Run a short self-test $ sudo smartctl -t short /dev/sda # Enable SMART monitoring service $ sudo systemctl enable --now smartmontools
Use Syncthing for Continuous Sync
Keep files in sync across multiple machines without a central server:
$ sudo apt install syncthing # Start Syncthing $ systemctl --user enable --now syncthing # Access the web UI # Open http://localhost:8384 in your browser # Create a systemd service for auto-start $ sudo apt install syncthing-systemd # Check sync status $ systemctl --user status syncthing
Network Management
Essential networking tools and configurations for Debian administrators
Network Scanning with nmap
Discover devices, open ports, and services on your network:
$ sudo apt install nmap # Scan your local network $ sudo nmap -sn 192.168.1.0/24 # Detailed port scan $ sudo nmap -sS -p 1-1000 192.168.1.100 # OS detection $ sudo nmap -O 192.168.1.100 # Scan common web ports $ sudo nmap -p 80,443,8080,8443 192.168.1.0/24
Set Up a Local DNS Cache with Dnsmasq
Speed up DNS resolution by caching queries locally:
$ sudo apt install dnsmasq # Point to local DNS cache $ echo "nameserver 127.0.0.1" | sudo tee /etc/resolv.conf # Configure upstream DNS servers $ sudo nano /etc/dnsmasq.conf # Add these lines: resolv-file=/etc/dnsmasq.resolv.conf cache-size=1000 log-queries # Set upstream DNS $ echo "nameserver 1.1.1.1" | sudo tee /etc/dnsmasq.resolv.conf $ echo "nameserver 8.8.8.8" | sudo tee -a /etc/dnsmasq.resolv.conf $ sudo systemctl restart dnsmasq
Monitor Network Traffic with nethogs
See which processes are using the most bandwidth in real-time:
$ sudo apt install nethogs # Monitor default interface $ sudo nethogs # Monitor specific interface $ sudo nethogs eth0 # Alternative: use iftop for connection-level view $ sudo apt install iftop $ sudo iftop -i eth0
Create a Wireless Access Point
Turn your Debian machine into a WiFi hotspot:
$ sudo apt install hostapd dnsmasq iptables # Configure hostapd $ sudo nano /etc/hostapd/hostapd.conf interface=wlan0 driver=nl80211 ssid=DebianHotspot hw_mode=g channel=6 wmm_enabled=0 macaddr_acl=0 auth_algs=1 wpa=2 wpa_passphrase=yourpassword wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP $ sudo systemctl enable --now hostapd
Personalize Your System
Make Debian truly yours with these customization techniques
Customize GRUB Boot Menu
Change the default boot behavior, timeout, and appearance of GRUB:
$ sudo nano /etc/default/grub # Key settings: GRUB_TIMEOUT=5 # Boot menu timeout GRUB_DEFAULT=0 # Default entry GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" GRUB_GFXMODE=1920x1080 # Boot menu resolution GRUB_THEME=/boot/grub/themes/debian/theme.txt # Apply changes $ sudo update-grub
Set Up a Custom Kernel
Install a newer or specialized kernel for better hardware support:
# Check current kernel $ uname -r # Install backports kernel (newer version) $ sudo apt install linux-image-amd64 -t bookworm-backports # Or install the cloud/server kernel $ sudo apt install linux-image-cloud-amd64 # Remove old kernels $ sudo apt autoremove --purge # Reboot into new kernel $ sudo reboot
Configure Power Management
Optimize power usage for laptops and desktops:
# Install power management tools $ sudo apt install tlp powertop # Enable TLP $ sudo systemctl enable --now tlp # Run power profile analysis $ sudo powertop # Auto-tune power settings $ sudo powertop --auto-tune # Check CPU frequency governor $ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor # Set to powersave for laptops $ echo powersave | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
Create Custom DEB Packages
Package your own applications for easy installation and management:
$ sudo apt install dpkg-dev devscripts # Create package structure $ mkdir -p myapp/DEBIAN $ mkdir -p myapp/usr/local/bin # Copy your application $ cp myapp-binary myapp/usr/local/bin/ # Create control file $ cat > myapp/DEBIAN/control <<'EOF' Package: myapp Version: 1.0.0 Section: utils Priority: optional Architecture: amd64 Maintainer: Your NameDescription: My custom application A brief description of what myapp does. EOF # Build the package $ dpkg-deb --build myapp # Install it $ sudo dpkg -i myapp.deb
Quick Cheat Sheet
Essential commands every Debian user should know at their fingertips
| Category | Command | Description |
|---|---|---|
| System Info | uname -a |
Display full system information |
| System Info | hostnamectl |
Show hostname and OS details |
| Package Mgmt | apt list --installed |
List all installed packages |
| Package Mgmt | apt search <name> |
Search for packages |
| Package Mgmt | apt show <name> |
Show package details |
| Services | systemctl list-units --failed |
List all failed services |
| Services | journalctl -xe |
View system logs with errors |
| Networking | ip addr |
Show network interfaces and IPs |
| Networking | ss -tulpn |
List all listening ports |
| Storage | lsblk |
List block devices |
| Storage | df -h |
Check disk space usage |
| Processes | htop |
Interactive process viewer |
| Users | useradd -m -s /bin/bash <name> |
Create a new user with home dir |
| Permissions | chmod 755 file |
Set read/write/execute permissions |
| Permissions | chown user:group file |
Change file ownership |
Pro Tip: Create Your Own Cheat Sheet
Save frequently used commands in a ~/.bash_aliases file and source it from your ~/.bashrc. You can also use tools like thefuck to automatically correct mistyped commands.