A comprehensive cheatsheet for Alpine Linux, covering package management, system administration, networking, and more. Alpine Linux is a security-oriented, lightweight Linux distribution based on musl libc and busybox.
# Update package index
apk update
# Upgrade all installed packages
apk upgrade
# Install a package
apk add <package-name>
# Remove a package
apk del <package-name>
# Search for a package
apk search <package-name>
# Show package info
apk info <package-name>
# List all installed packages
apk list --installed
# Add package from testing repository
apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing <package-name>
# Add multiple packages
apk add package1 package2 package3
# Clean package cache
apk cache clean
# Start a service
rc-service <service-name> start
# Stop a service
rc-service <service-name> stop
# Restart a service
rc-service <service-name> restart
# Add service to default runlevel
rc-update add <service-name> default
# Remove service from default runlevel
rc-update del <service-name> default
# List all services
rc-status
# Show system information
uname -a
# Show disk usage
df -h
# Show memory usage
free -h
# Show running processes
ps aux
# Show system uptime
uptime
# Show network interfaces
ip addr show
# Configure network interface
setup-interfaces
# Test network connectivity
ping -c 4 google.com
# Show routing table
ip route show
# Edit network configuration
vi /etc/network/interfaces
# Add a new user
adduser <username>
# Add user to group
addgroup <username> <groupname>
# Change password
passwd <username>
# Delete user
deluser <username>
# List all users
cat /etc/passwd
# Create directory
mkdir <directory-name>
# Remove directory
rm -r <directory-name>
# Copy files
cp <source> <destination>
# Move/rename files
mv <source> <destination>
# Change permissions
chmod <permissions> <file>
# Change ownership
chown <user>:<group> <file>
# Install Docker
apk add docker
# Start Docker service
rc-service docker start
# Enable Docker at boot
rc-update add docker default
# Check disk space
df -h
# Check directory size
du -sh <directory>
# Mount a device
mount /dev/<device> /mnt/<mountpoint>
# Unmount a device
umount /mnt/<mountpoint>
# Create tar archive
tar -czf backup.tar.gz /path/to/backup
# Extract tar archive
tar -xzf backup.tar.gz
# Create system backup (root required)
lbu package /media/backup.apkovl.tar.gz
/etc/apk/repositories
- Package repositories/etc/network/interfaces
- Network configuration/etc/hostname
- System hostname/etc/hosts
- Host mappings/etc/resolv.conf
- DNS configuration# Set environment variable
export VARIABLE=value
# View all environment variables
env
# Add permanent environment variable
echo "export VARIABLE=value" >> ~/.profile
# View system logs
less /var/log/messages
# View boot messages
dmesg
# Follow log in real-time
tail -f /var/log/messages
# Install iptables
apk add iptables
# Allow SSH (port 22)
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# Save iptables rules
/etc/init.d/iptables save
# Restore iptables rules
/etc/init.d/iptables restart
# Generate SSH key
ssh-keygen -t rsa -b 4096
# Copy SSH key to remote server
ssh-copy-id user@remote-server
# Edit SSH configuration
vi /etc/ssh/sshd_config