From 9d1681dab090a701d854316886d4c4c713630cf2 Mon Sep 17 00:00:00 2001 From: Jager Date: Sun, 2 Mar 2025 21:46:42 -0500 Subject: [PATCH] feat: add comprehensive Alpine Linux cheatsheet --- source/_posts/alpine-linux.md | 278 ++++++++++++++++++++++++++++++++++ 1 file changed, 278 insertions(+) create mode 100644 source/_posts/alpine-linux.md diff --git a/source/_posts/alpine-linux.md b/source/_posts/alpine-linux.md new file mode 100644 index 0000000..878c2d0 --- /dev/null +++ b/source/_posts/alpine-linux.md @@ -0,0 +1,278 @@ +--- +title: Alpine Linux +date: 2024-03-20 12:00:00 +icon: icon-alpine +background: bg-blue-600 +tags: + - linux + - server + - container +categories: + - Operating System +intro: 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. +--- + +# Alpine Linux Cheatsheet + +## Package Management (apk) + +### Basic Package Operations +```bash +# Update package index +apk update + +# Upgrade all installed packages +apk upgrade + +# Install a package +apk add + +# Remove a package +apk del + +# Search for a package +apk search + +# Show package info +apk info + +# List all installed packages +apk list --installed +``` + +### Advanced Package Operations +```bash +# Add package from testing repository +apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing + +# Add multiple packages +apk add package1 package2 package3 + +# Clean package cache +apk cache clean +``` + +## System Administration + +### Service Management (OpenRC) +```bash +# Start a service +rc-service start + +# Stop a service +rc-service stop + +# Restart a service +rc-service restart + +# Add service to default runlevel +rc-update add default + +# Remove service from default runlevel +rc-update del default + +# List all services +rc-status +``` + +### System Information +```bash +# Show system information +uname -a + +# Show disk usage +df -h + +# Show memory usage +free -h + +# Show running processes +ps aux + +# Show system uptime +uptime +``` + +### Network Configuration +```bash +# 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 +``` + +### User Management +```bash +# Add a new user +adduser + +# Add user to group +addgroup + +# Change password +passwd + +# Delete user +deluser + +# List all users +cat /etc/passwd +``` + +## File System Operations + +### Basic File Operations +```bash +# Create directory +mkdir + +# Remove directory +rm -r + +# Copy files +cp + +# Move/rename files +mv + +# Change permissions +chmod + +# Change ownership +chown : +``` + +## Container Operations + +### Docker Support +```bash +# Install Docker +apk add docker + +# Start Docker service +rc-service docker start + +# Enable Docker at boot +rc-update add docker default +``` + +## System Maintenance + +### Disk Operations +```bash +# Check disk space +df -h + +# Check directory size +du -sh + +# Mount a device +mount /dev/ /mnt/ + +# Unmount a device +umount /mnt/ +``` + +### Backup and Restore +```bash +# 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 +``` + +## Tips and Tricks + +### Common Configuration Files +- `/etc/apk/repositories` - Package repositories +- `/etc/network/interfaces` - Network configuration +- `/etc/hostname` - System hostname +- `/etc/hosts` - Host mappings +- `/etc/resolv.conf` - DNS configuration + +### Environment Variables +```bash +# Set environment variable +export VARIABLE=value + +# View all environment variables +env + +# Add permanent environment variable +echo "export VARIABLE=value" >> ~/.profile +``` + +### System Logs +```bash +# View system logs +less /var/log/messages + +# View boot messages +dmesg + +# Follow log in real-time +tail -f /var/log/messages +``` + +## Security + +### Firewall (using iptables) +```bash +# 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 +``` + +### SSH Configuration +```bash +# 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 +``` + +## Troubleshooting + +### Common Commands +```bash +# Check system logs for errors +dmesg | grep -i error + +# Check service status +rc-service status + +# Check system resource usage +top + +# Check network connections +netstat -tuln + +# Check disk health +smartctl -a /dev/sda # Requires smartmontools package +``` \ No newline at end of file