-
-
Notifications
You must be signed in to change notification settings - Fork 2
Arch Linux Security Configuration
Complete beginner-friendly guide to securing Arch Linux, including firewall setup, user management, encryption, and security best practices.
- Firewall Setup
- User Management
- File Permissions
- Disk Encryption
- SSH Security
- System Updates
- Security Best Practices
Install UFW:
# Install UFW
sudo pacman -S ufw
# Enable firewall
sudo ufw enable
# Check status
sudo ufw statusCommon rules:
# Allow SSH
sudo ufw allow ssh
# Allow HTTP/HTTPS
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
# Deny port
sudo ufw deny 8080/tcpInstall firewalld:
# Install firewalld
sudo pacman -S firewalld
# Enable and start service (recommended method)
sudo systemctl enable --now firewalld
# Check status
sudo firewall-cmd --stateConfigure zones:
# List zones
sudo firewall-cmd --get-zones
# Set default zone
sudo firewall-cmd --set-default-zone public
# Allow service
sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --reloadAdvanced firewall:
# Install iptables
sudo pacman -S iptables
# Basic rules
sudo iptables -A INPUT -i lo -j ACCEPT
sudo iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
sudo iptables -A INPUT -j DROP
# Save rules
sudo iptables-save > /etc/iptables/iptables.rulesAdd users:
# Create user
sudo useradd -m -G wheel username
# Set password
sudo passwd usernameConfigure sudo:
# Edit sudoers
sudo visudoEnsure wheel group:
%wheel ALL=(ALL) ALL
Delete users:
# Remove user
sudo userdel username
# Remove with home
sudo userdel -r usernameLock/unlock accounts:
# Lock account
sudo passwd -l username
# Unlock account
sudo passwd -u usernamePermission format:
-rwxr-xr-x
││││││││││
││││││││└── Other: execute
│││││││└─── Other: read
││││││└──── Group: execute
│││││└───── Group: read
││││└────── Owner: execute
│││└─────── Owner: write
││└──────── Owner: read
│└───────── File type (- = file, d = directory)
Change permissions:
# Set permissions
chmod 755 file
chmod u+x file
chmod g-w file
# Recursive
chmod -R 755 directoryPermission values:
-
4: Read -
2: Write -
1: Execute -
7: Read + Write + Execute -
5: Read + Execute
Change owner:
# Change owner
sudo chown user:group file
# Recursive
sudo chown -R user:group directoryEncrypt disk:
# Install cryptsetup
sudo pacman -S cryptsetup
# Encrypt partition
sudo cryptsetup luksFormat /dev/sda2
# Open encrypted partition
sudo cryptsetup open /dev/sda2 cryptroot
# Format
sudo mkfs.ext4 /dev/mapper/cryptroot
# Mount
sudo mount /dev/mapper/cryptroot /mntEncrypt swap:
# Create swap
sudo cryptsetup -d /dev/urandom open --type plain /dev/sda3 swap
# Format swap
sudo mkswap /dev/mapper/swap
# Enable swap
sudo swapon /dev/mapper/swapInstall OpenSSH:
# Install SSH
sudo pacman -S openssh
# Enable service
sudo systemctl enable sshd
sudo systemctl start sshdSecure SSH:
# Edit SSH config
sudo vim /etc/ssh/sshd_configSecurity settings:
# Disable root login
PermitRootLogin no
# Change port
Port 2222
# Disable password auth (use keys)
PasswordAuthentication no
# Allow specific users
AllowUsers username
Restart SSH:
sudo systemctl restart sshdGenerate key:
# Generate key pair
ssh-keygen -t ed25519 -C "your_email@example.com"
# Copy public key
ssh-copy-id user@serverUpdate system:
# Update packages
sudo pacman -Syu
# Check for updates
pacman -QuCheck security:
# Install arch-audit
sudo pacman -S arch-audit
# Check vulnerabilities
arch-auditSetup auto-updates (optional):
# Install pacman-contrib
sudo pacman -S pacman-contrib
# Create update script
sudo vim /usr/local/bin/arch-update.shBest practices:
-
Keep system updated
sudo pacman -Syu
-
Use strong passwords
- Long, complex passwords
- Different passwords for different accounts
-
Enable firewall
sudo ufw enable -
Limit sudo access
- Only add trusted users to wheel
-
Disable unnecessary services
sudo systemctl disable service-name
Additional security:
# Install security tools
sudo pacman -S fail2ban rkhunter
# Configure fail2ban
sudo systemctl enable fail2ban
sudo systemctl start fail2banCheck system:
# Install audit tools
sudo pacman -S audit
# Enable audit
sudo systemctl enable auditd
sudo systemctl start auditdThis guide covered:
- Firewall - UFW, firewalld, iptables
- User management - Create/remove users
- File permissions - Set proper permissions
- Encryption - Disk encryption
- SSH security - Secure SSH
- Updates - Keep system updated
- Best practices - Security tips
Key Takeaways:
- Enable firewall
- Use strong passwords
- Limit sudo access
- Keep system updated
- Encrypt sensitive data
- Secure SSH
- Arch Linux Networking - Network setup
- Arch Linux System Configuration - System setup
- ArchWiki Security: https://wiki.archlinux.org/title/Security
This guide is based on the ArchWiki. For the most up-to-date information, always refer to the official ArchWiki.