Why Linux?

Linux

Nearly every self-hosted container image, NAS operating system, and home-lab hypervisor runs on Linux. Knowing twenty core commands and how to read service logs turns mysterious errors into quick fixes.

Choosing a Distribution

DistributionBest ForPackage ManagerNotes
Debian 12Headless servers, stabilityaptPredictable releases, low overhead
Ubuntu Server 24.04General servers, wide tutorialsaptLTS updates and broad driver support
Alpine LinuxMinimal container basesapkTiny footprint (~5MB base image)
Proxmox VEVMs and LXC containersaptDebian-based Type-1 hypervisor
TrueNAS ScaleStorage + containersApplianceZFS pools with browser admin UI
UnraidMixed-drive home NAS + VMsSlackware basePaid licence, flexible parity array
Arch LinuxDesktop learningpacmanRolling release, rarely ideal for unattended servers

Recommended starting point: Debian 12 or Ubuntu Server 24.04 LTS for straightforward Docker compatibility and long security support windows.

Essential Commands

File Operations

ls -la              # List files with details and hidden files
cd /path/to/dir     # Change directory
pwd                 # Print working directory
cp file1 file2      # Copy
mv file1 file2      # Move/rename
rm file             # Delete (careful: no recycle bin)
rm -rf directory    # Delete directory and contents (verify path first)
mkdir -p path/to/dir # Create nested directories
cat file            # Display file contents
less file           # Page through a file (q to quit)
head -20 file       # First 20 lines
tail -20 file       # Last 20 lines
tail -f file        # Follow file in real-time (great for logs)

System Information

uname -a            # Kernel and architecture
hostname            # Machine name
uptime              # Time since last reboot and load averages
free -h             # Memory usage
df -h               # Disk space usage
du -sh /path        # Size of a directory
top / htop          # Running processes
lsblk               # Block devices (disks, partitions)
ip addr             # Network interfaces and IP addresses
ss -tlnp            # Listening TCP ports

Package Management (Debian and Ubuntu)

sudo apt update              # Refresh package lists
sudo apt upgrade             # Upgrade installed packages
sudo apt install <package>   # Install a package
sudo apt remove <package>    # Remove a package
sudo apt autoremove          # Remove unused dependencies

File Permissions

Linux splits file permissions into three scopes: owner, group, and others.

-rw-r--r-- 1 user group 4096 Mar 15 README.md
 │││ │││ │││
 │││ │││ └── Others: read only
 │││ └──── Group: read only
 └────── Owner: read + write

Common permission commands:

chmod 600 .env          # Owner read/write only (secrets)
chmod 644 config.yml    # Owner read/write, others read
chmod 755 script.sh     # Owner all, others read/execute
chmod -R 755 /data      # Recursive
chown user:group file   # Change ownership
chown -R 1000:1000 /data # Common for Docker volumes

Systemd: Managing Services

Modern Linux distributions manage background daemons through systemd:

sudo systemctl start docker      # Start a service
sudo systemctl stop docker       # Stop a service
sudo systemctl restart docker    # Restart
sudo systemctl enable docker     # Start on boot
sudo systemctl disable docker    # Don't start on boot
sudo systemctl status docker     # Check status
journalctl -u docker -f          # Follow service logs

Creating a Custom Service

# /etc/systemd/system/myapp.service
[Unit]
Description=My Application
After=network.target

[Service]
Type=simple
User=appuser
WorkingDirectory=/opt/myapp
ExecStart=/opt/myapp/run.sh
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now myapp

SSH: Remote Access

ssh user@server-ip          # Connect
ssh -p 2222 user@server-ip  # Non-standard port
scp file user@server:/path  # Copy file to server
scp user@server:/path file  # Copy file from server
rsync -avz /local/ user@server:/remote/  # Sync directories

SSH Config File

Store aliases in ~/.ssh/config to avoid repeating flags:

Host mynas
    HostName 192.0.2.100
    User admin
    Port 2222
    IdentityFile ~/.ssh/id_ed25519

Host docker-server
    HostName 192.0.2.101
    User deploy

Connect afterwards with ssh mynas.

Troubleshooting Workflow

Read the Logs

# System logs
journalctl -xe                    # Recent errors
journalctl --since "1 hour ago"   # Last hour

# Docker container logs
docker logs container-name
docker logs -f --tail 50 container-name  # Follow last 50 lines

# Application-specific
grep -i error /var/log/syslog

Check Connectivity

ping 8.8.8.8                    # Check raw IP routing
ping example.com                # Check DNS resolution
curl -I https://example.com     # Check HTTP/TLS response
dig yourdomain.com              # Inspect DNS records
traceroute 8.8.8.8              # Trace network hops
ss -tlnp                        # Confirm service ports are listening

Check Resource Limits

htop                            # Interactive CPU and RAM viewer
df -h                           # Check for full filesystems
free -h                         # Check available RAM and swap
docker stats                    # Per-container CPU and RAM
iostat                          # Disk I/O bottlenecks

Product links may include affiliate partnerships. See our affiliate disclosure for details.