Linux Security
Learn about Linux security, system hardening, and security best practices.
Linux manthan
Security is a critical aspect of Linux system administration. This guide covers essential security concepts, tools, and best practices for securing Linux systems.
System Hardening
Basic Hardening
-
System Updates
# Regular updates apt update && apt upgrade # Debian/Ubuntu yum update # RHEL/CentOS
-
Service Management
# Disable unnecessary services systemctl disable service # Check running services systemctl list-units --type=service
-
File Permissions
# Secure file permissions chmod 600 /path/to/file chown root:root /path/to/file
Advanced Hardening
-
SELinux/AppArmor
# Check SELinux status sestatus # Configure AppArmor aa-status
-
System Configuration
# Secure system parameters sysctl -w net.ipv4.tcp_syncookies=1 sysctl -w net.ipv4.conf.all.accept_redirects=0
Access Control
User Authentication
-
Password Policies
# Configure password policies vi /etc/security/pwquality.conf # Set password expiration chage -M 90 username
-
SSH Security
# SSH configuration vi /etc/ssh/sshd_config # Disable root login PermitRootLogin no # Use key authentication PasswordAuthentication no
File Permissions
# Set proper permissions
chmod 750 /home/user
chmod 600 ~/.ssh/authorized_keys
# Set ACLs
setfacl -m u:user:rx /path/to/directory
Network Security
Firewall Configuration
# UFW (Ubuntu)
ufw default deny incoming
ufw default allow outgoing
ufw allow ssh
ufw enable
# Firewalld (RHEL/CentOS)
firewall-cmd --permanent --add-service=ssh
firewall-cmd --reload
Network Hardening
-
TCP Wrappers
# Configure access control vi /etc/hosts.allow vi /etc/hosts.deny
-
Network Parameters
# Secure network settings sysctl -w net.ipv4.conf.all.accept_source_route=0 sysctl -w net.ipv4.conf.all.accept_redirects=0
Security Monitoring
Log Monitoring
# Monitor authentication logs
tail -f /var/log/auth.log
# Monitor system logs
tail -f /var/log/syslog
# Monitor failed login attempts
lastb
Security Tools
-
Intrusion Detection
# Install and configure AIDE apt install aide aideinit # Regular checks aide --check
-
Vulnerability Scanning
# Run security audit lynis audit system # Network scanning nmap -sV -sS target
Encryption
Disk Encryption
# LUKS encryption
cryptsetup luksFormat /dev/sda1
cryptsetup luksOpen /dev/sda1 secure
# Mount encrypted volume
mount /dev/mapper/secure /mnt/secure
SSL/TLS Configuration
# Generate SSL certificate
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout private.key -out certificate.crt
# Configure SSL in Apache
SSLEngine on
SSLCertificateFile /path/to/certificate.crt
SSLCertificateKeyFile /path/to/private.key
Security Best Practices
-
System Security
- Regular updates
- Minimal installation
- Secure boot
- File integrity monitoring
-
Access Control
- Strong passwords
- Two-factor authentication
- Principle of least privilege
- Regular access reviews
-
Network Security
- Firewall rules
- VPN configuration
- Secure protocols
- Network monitoring
-
Data Security
- Encryption at rest
- Secure backups
- Data classification
- Access controls
Incident Response
Detection
# Check for suspicious processes
ps aux | grep suspicious
# Check for unusual network connections
netstat -tuln
# Check file integrity
aide --check
Response
-
Immediate Actions
- Isolate affected systems
- Preserve evidence
- Document incident
- Notify stakeholders
-
Recovery
- Restore from backup
- Patch vulnerabilities
- Update security measures
- Review logs
Next Steps
Continue learning about:
- Advanced security tools
- Security automation
- Compliance frameworks
- Security auditing
- Incident response procedures