Posted January 19Jan 19 You are reading Part 34 of the 57-part series: Harden and Secure Linux Servers. [Level 4]This series covers progressive security measures, from fundamental hardening techniques to enterprise-grade defense strategies. Each article delves into a specific security practice, explaining its importance and providing step-by-step guidance for implementation.To explore more security best practices, visit the main guide for a full breakdown of all levels and recommendations.Data Loss Prevention (DLP) ensures that sensitive data remains protected from unauthorized access, accidental leaks, and intentional breaches. DLP is essential for:✅ Preventing unauthorized file modifications and access.✅ Protecting confidential information from data exfiltration.✅ Ensuring compliance with security standards (GDPR, HIPAA, PCI-DSS).By implementing DLP measures, you reduce the risk of data breaches and ensure data integrity.How to Implement Data Loss Prevention in Linux1. Track Sensitive Data Changes with File Integrity Monitoring (FIM)Use AIDE (Advanced Intrusion Detection Environment) to monitor file modifications in critical directories.Install and Configure AIDEInstall AIDE (Debian/Ubuntu):sudo apt install aide -y For CentOS/RHEL:sudo yum install aide -y Initialize the AIDE database:sudo aideinit sudo mv /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz Configure AIDE to monitor sensitive directories:sudo nano /etc/aide/aide.conf Add directories to monitor:/etc/ p /home/user/Documents/ p /var/log/ p (Monitors /etc/, /home/user/Documents/, and /var/log/ for unauthorized changes.)Schedule regular integrity checks:sudo crontab -e Add a scheduled task (runs daily at 3 AM):0 3 * * * /usr/bin/aide --check | mail -s "AIDE Integrity Report" admin@example.com 2. Encrypt Sensitive Data with GPG or OpenSSLEncryption ensures that even if data is accessed, it remains unreadable without the correct decryption key.Encrypt Files Using GPG (GnuPG)Encrypt a file with a passphrase:gpg --symmetric --cipher-algo AES256 confidential.txt Decrypt the file when needed:gpg --output confidential.txt --decrypt confidential.txt.gpg Encrypt Data with OpenSSLEncrypt a file with AES-256:openssl enc -aes-256-cbc -salt -in confidential.txt -out confidential.enc Decrypt the file:openssl enc -aes-256-cbc -d -in confidential.enc -out confidential.txt 3. Set Strict File Permissions for Sensitive DataRestrict access to sensitive files to authorized users only.Restrict File Access Using chmodSet strict permissions (owner-only access):sudo chmod 600 /home/user/confidential.txt Restrict entire directories:sudo chmod -R 700 /home/user/private/ (Only the owner can access this directory.)Use Access Control Lists (ACLs) for Fine-Grained AccessGrant read-only access to a specific user:sudo setfacl -m u:username:r /home/user/confidential.txt Verify ACL settings:getfacl /home/user/confidential.txt 4. Prevent Unauthorized Data TransfersBlock USB Storage Devices (Prevent Data Exfiltration)Disable USB mass storage module:echo "blacklist usb-storage" | sudo tee -a /etc/modprobe.d/blacklist.conf Reload system modules:sudo modprobe -r usb-storage Restrict Data Transfers with iptablesBlock unauthorized outbound traffic:sudo iptables -A OUTPUT -p tcp --dport 21 -j DROP # Blocks FTP sudo iptables -A OUTPUT -p tcp --dport 22 -j DROP # Blocks SSH File Transfers sudo iptables -A OUTPUT -p tcp --dport 80 -j DROP # Blocks HTTP Uploads Allow only trusted IPs to transfer data:sudo iptables -A OUTPUT -p tcp -d trusted_ip --dport 22 -j ACCEPT 5. Monitor and Log Access to Sensitive FilesEnable Auditd to Log File AccessInstall auditd (Debian/Ubuntu):sudo apt install auditd -y (Already installed by default on CentOS/RHEL.)Monitor a specific file for access attempts:sudo auditctl -w /home/user/confidential.txt -p war -k sensitive_file_access Check audit logs for file access:sudo ausearch -k sensitive_file_access --start today Best Practices for Data Loss Prevention (DLP)✅ Regularly back up encrypted copies of sensitive data (rsync -avz /secure_data /backup).✅ Monitor logs (/var/log/auth.log) for unauthorized access attempts.✅ Use Intrusion Detection Systems (IDS) like OSSEC or Wazuh to alert on unauthorized file changes.✅ Restrict sensitive data access to specific users and groups.By implementing Data Loss Prevention (DLP) measures, you secure critical information, prevent unauthorized access, and ensure compliance with data protection regulations, keeping your Linux server safe from data breaches.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.