-
-
Notifications
You must be signed in to change notification settings - Fork 1
Linux Security Configuration
Complete beginner-friendly guide to securing your Linux system, covering Arch Linux, CachyOS, and other distributions including firewall setup, user management, file permissions, encryption, SSH security, and best practices.
- Understanding Linux Security
- Firewall Configuration
- User Management
- File Permissions
- Disk Encryption
- SSH Security
- System Updates
- Security Best Practices
Linux security is based on several principles:
- Least privilege: Users have minimum necessary access
- Defense in depth: Multiple security layers
- Regular updates: Keep system updated
- Strong passwords: Use secure passwords
- Access control: Control who can access what
Multiple layers:
- Firewall: Network security
- User permissions: File access control
- Encryption: Data protection
- Updates: Security patches
- Monitoring: Detect issues
Install UFW:
# Arch/CachyOS
sudo pacman -S ufw
# Debian/Ubuntu
sudo apt install ufw
# Fedora
sudo dnf install ufwEnable firewall:
# 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:
# Arch/CachyOS
sudo pacman -S firewalld
# Debian/Ubuntu
sudo apt install firewalld
# Fedora (usually pre-installed)
sudo dnf install firewalldEnable service:
sudo systemctl enable --now firewalldConfigure 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 user:
# Create user
sudo useradd -m -G wheel username
# Set password
sudo passwd usernameConfigure sudo:
# Edit sudoers
sudo visudo
# Ensure wheel group has sudo
%wheel ALL=(ALL) ALLSecure root:
# Lock root account
sudo passwd -l root
# Or disable root login in SSH
# Edit /etc/ssh/sshd_config
# Set: PermitRootLogin noFile permissions:
# View permissions
ls -l file
# Output example:
# -rw-r--r-- 1 user group 1024 Jan 15 10:00 filePermission bits:
- Owner: Read, Write, Execute
- Group: Read, Write, Execute
- Others: Read, Write, Execute
Change permissions:
# Set permissions
chmod 755 file
chmod u+x file
chmod g-w file
# Recursive
chmod -R 755 directoryChange owner:
# Change owner
sudo chown user:group file
# Recursive
sudo chown -R user:group directoryEncrypt partition:
# Encrypt partition
sudo cryptsetup luksFormat /dev/sda2
# Open encrypted partition
sudo cryptsetup open /dev/sda2 cryptroot
# Format
sudo mkfs.ext4 /dev/mapper/cryptrootSee Disk Encryption for detailed guide.
Edit SSH config:
# Edit config
sudo vim /etc/ssh/sshd_configSecurity settings:
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
MaxAuthTries 3
Restart SSH:
sudo systemctl restart sshdSee SSH Configuration for detailed guide.
Update system:
# Arch/CachyOS
sudo pacman -Syu
# Debian/Ubuntu
sudo apt update && sudo apt upgrade
# Fedora
sudo dnf updateWhy updates matter:
- Security patches: Fix vulnerabilities
- Bug fixes: Improve stability
- New features: Get latest features
Security checklist:
- Keep system updated: Regular updates
- Use firewall: Block unnecessary ports
- Strong passwords: Use secure passwords
- Disable root login: Use sudo instead
- Encrypt sensitive data: Protect important files
- Regular backups: Backup important data
- Monitor logs: Check for suspicious activity
Install fail2ban:
# Arch/CachyOS
sudo pacman -S fail2ban
# Debian/Ubuntu
sudo apt install fail2ban
# Fedora
sudo dnf install fail2banEnable:
sudo systemctl enable fail2ban
sudo systemctl start fail2banThis guide covered security configuration for Arch Linux, CachyOS, and other distributions, including firewall, user management, file permissions, encryption, SSH, and best practices.
- SSH Configuration - SSH setup
- System Hardening - Advanced security
- Disk Encryption - Encryption guide
- ArchWiki Security: https://wiki.archlinux.org/title/Security
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.