DEV Community

Cover image for 5 Security Practices Often Overlooked During Self-Hosting
Mustafa ERBAY
Mustafa ERBAY

Posted on • Originally published at mustafaerbay.com.tr

5 Security Practices Often Overlooked During Self-Hosting

When managing your own servers, basic firewall rules and locking down SSH access are usually the first steps that come to mind. However, there are critical security practices in self-hosting environments that are often overlooked and can seriously threaten system integrity. This post will detail 5 important security steps that can be missed during self-hosting, explaining why each is important and how it can be implemented with concrete examples.

These approaches have been shaped by years of experience across various system and network infrastructures. My goal is to provide not just "what to do," but also the answers to "why to do it," helping you build more robust and resilient self-hosting solutions. Security is not a one-time task but a continuous process, and these practices are the cornerstones of that process.

1. Neglected Patch Management and Outdated Software

Keeping your systems up-to-date is the most fundamental way to close known security vulnerabilities, and it's often not given enough importance by many self-hosting users. Using an old version of a software means leaving an open door for exploitation of its identified and published CVEs (Common Vulnerabilities and Exposures). This poses a significant risk, especially for internet-facing services.

Up-to-date software not only fixes security vulnerabilities but also offers performance improvements and new features. Regular patch management ensures that attackers looking for easy targets will bypass your system. In many cases, a server compromise stems from a simple lack of patching.

Why It's Important

The continuous publication of CVEs indicates that new vulnerabilities are discovered every day. While most of these vulnerabilities are quickly patched by vendors, users may take time to apply these patches or miss them entirely. Vulnerabilities in kernel modules or bugs in critical services can lead to a complete system takeover.

For instance, a vulnerability found in kernel modules like algif_aead (such as CVE-2026-31431) can weaken the system at the kernel level. While such situations can be resolved with a simple apt upgrade or dnf update command, neglecting them can lead to major problems.

How to Implement

Configuring automatic patch management on Linux systems significantly reduces this risk. On Debian-based systems, the unattended-upgrades package can automatically download and install security updates in the background. This reduces the need for manual intervention while ensuring your system stays up-to-date.

sudo apt update
sudo apt install unattended-upgrades
sudo dpkg-reconfigure unattended-upgrades
Enter fullscreen mode Exit fullscreen mode

These commands will present a configuration wizard that asks you about the frequency and types of packages for automatic updates. Generally, it's preferred to automatically install security updates. Additionally, by monitoring system calls and file access with the auditd subsystem, you can detect unexpected behavior.

💡 Considerations for Automatic Updates

While automatic updates offer convenience, they can sometimes lead to incompatibilities or service interruptions. Therefore, it's a good strategy to test automatic updates in a staging environment before applying them to critical systems, or to only automate security patches. Kernel updates often require a system reboot.

2. Improper Network Segmentation and Exposed Services

In many self-hosting setups, all services run on the same network segment, which lays the groundwork for a vulnerability to spread across the entire system. Having a web server accessible from the internet on the same network as a sensitive database server or management interfaces multiplies the security risk. When one service is compromised, it becomes much easier for an attacker to move laterally within the network.

Network segmentation is the practice of dividing a network into different logical or physical sections. Each section has its own security policies and access controls. This is vital for containing the impact of an attack and better protecting sensitive systems.

Why It's Important

In a flat network structure, even a simple vulnerability in a web application can open a path to other servers or data on the same network. For example, an attacker gaining access to a web server can easily reach an internal database server or the management SSH port. This poses significant risks, especially in scenarios like a manufacturing company's ERP system where operator screens and critical database servers are on the same network.

Internal network segmentation and the use of VLANs are key to minimizing these risks.

How to Implement

A multi-layered approach can be taken to implement network segmentation:

  1. VLAN Segmentation: Virtual Local Area Networks (VLANs) can be used to create logically separate networks on a physical network. This allows you to create a separate VLAN for your web servers, another for your database servers, and another for management, for example. Switch hardening (DHCP snooping, DAI, IP source guard) further strengthens this layer.
  2. Firewall Rules: Firewall rules must be defined to control traffic between each segment. Tools like ufw (Uncomplicated Firewall) or iptables can be used to restrict incoming and outgoing traffic to specific ports and IP addresses.

    # Allow external access only to SSH (22) and HTTP/HTTPS (80, 443) ports
    sudo ufw default deny incoming
    sudo ufw default allow outgoing
    sudo ufw allow ssh
    sudo ufw allow http
    sudo ufw allow https
    sudo ufw enable
    
  3. Using a Reverse Proxy: It's a good practice to place your web applications behind a Nginx reverse proxy rather than exposing them directly to the internet. Nginx can route traffic to specific services while providing additional security layers like DDoS mitigation and rate limiting.

    server {
        listen 80;
        server_name yourdomain.com;
        return 301 https://$host$request_uri;
    }
    
    server {
        listen 443 ssl;
        server_name yourdomain.com;
        ssl_certificate /etc/nginx/ssl/yourdomain.com.crt;
        ssl_certificate_key /etc/nginx/ssl/yourdomain.com.key;
    
        location / {
            proxy_pass http://localhost:8080; # Address of your internal application
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }
    }
    

This layered approach makes it harder for an attacker to move through your network and helps you better protect your sensitive systems. Zero-trust architectures are also based on these principles; no internal or external resource is automatically trusted.

3. Weak Authentication and Authorization Mechanisms

Using default or easily guessable passwords is one of the most common security vulnerabilities encountered in self-hosting environments and is often the first target of automated attacks. Using weak authentication mechanisms for SSH access, web interfaces, database users, and other services significantly increases the probability of system compromise.

Authentication is the process of verifying a user's identity; authorization is the process of determining which resources a verified user can access. Both are critical for strong security.

Why It's Important

Botnets and automated attack tools focus on scanning all publicly accessible SSH ports and trying default or weak passwords. Such attacks can perform thousands of attempts per second, and if you have a weak password, your system's compromise is a matter of time. Single-factor authentication means that if an attacker guesses your password, they gain full access.

Beyond this, authorizing a user for resources they don't need also poses a risk. The Principle of Least Privilege states that a user or service should only have the minimum privileges necessary to perform its function. Excessive privileges amplify the impact of an attack in case of a vulnerability. I apply these principles by using robust patterns like JWT/OAuth2 in the backend of my own side projects.

How to Implement

The following steps can be taken to implement strong authentication and authorization practices:

  1. Strong and Unique Passwords: Use long, complex, and unique passwords for all user accounts. Password managers can help with this. Change default passwords immediately.
  2. SSH Key-Based Authentication: Disable password-based authentication for SSH and enforce key-based authentication. This makes guessing a password impossible and is more secure. Don't forget to use a passphrase for your keys.

    # Update the following lines in /etc/ssh/sshd_config
    PasswordAuthentication no
    PermitRootLogin no
    PubkeyAuthentication yes
    
  3. Two-Factor Authentication (2FA): Enable 2FA wherever possible. This means that even if an attacker knows your password, they cannot access the system without a second factor of authentication (e.g., a mobile app code or a physical key).

  4. Use fail2ban: fail2ban is a tool that monitors failed login attempts and automatically blocks malicious IP addresses. It can be configured for SSH, web servers (Nginx/Apache), and other services.

    sudo apt install fail2ban
    # Define a rule for SSH in /etc/fail2ban/jail.local
    [sshd]
    enabled = true
    port = ssh
    filter = sshd
    logpath = /var/log/auth.log
    maxretry = 3
    bantime = 1h
    
  5. Principle of Least Privilege: Grant user and service accounts only the minimum privileges they need. Use normal users with sudo privileges instead of the root user, and monitor sudo command usage with auditd. In a production ERP system, defining separate database users for operator screens and data analysis is a concrete example of this principle.

ℹ️ Importance of Authorization Processes

Not only authentication but also authorization processes should be regularly reviewed. Permissions that accumulate or are forgotten over time can become hidden sources of risk for systems. Role-Based Access Control (RBAC) offers a good model for this.

4. Insufficient Logging and Monitoring Practices

Logging and monitoring mechanisms, which are critical for detecting and responding to security incidents, are often missing in the setups of many self-hosting individuals. When an attack occurs or a security vulnerability is discovered, it's nearly impossible to understand what happened, determine the scope of the attack, and prevent future attacks without sufficient log records.

Logs record all types of activity on the system: login attempts, file access, service errors, network connections, and more. Monitoring involves tracking these logs and system metrics (CPU, memory, disk usage, network traffic) in real-time and detecting anomalies.

Why It's Important

Logs are invaluable for understanding a system's security posture. If an attacker manages to infiltrate a system, one of their first actions will be to delete or modify logs. Insufficient logging or logs being stored in a decentralized manner makes it difficult to notice such actions. Furthermore, operational issues like resource consumption, service outages, or unexpected behavior can also be detected through logs.

Misconfigured journald rate limits or insufficient use of auditd can lead to important security events being overlooked. auditd, in particular, is a powerful tool for monitoring file integrity (file integrity monitoring) and can provide immediate alerts if any critical file is modified.

How to Implement

The following steps are recommended to implement effective logging and monitoring practices:

  1. Centralized Logging: If possible, collect logs from all your systems on a central server (e.g., using rsyslog or syslog-ng). This prevents logs from being easily deleted by an attacker and simplifies analysis. journald is also a powerful local logging system.

    # Show the last 100 journald entries
    journalctl -n 100
    
    # Show logs for a specific service
    journalctl -u nginx.service
    
    # Show logs for a specific time range
    journalctl --since "2026-08-11 10:00:00" --until "2026-08-12 10:00:00"
    
  2. Log Rotation: Log files can grow quickly and fill up disk space. The logrotate tool automatically compresses, archives, and deletes log files after a certain period. This allows you to manage disk space while making historical data accessible.

    # Example content for /etc/logrotate.d/nginx
    /var/log/nginx/*.log {
        daily
        missingok
        rotate 14
        compress
        delaycompress
        notifempty
        create 0640 www-data adm
        sharedscripts
        postrotate
            if [ -f /var/run/nginx.pid ]; then
                kill -USR1 `cat /var/run/nginx.pid`
            fi
        endscript
    }
    
  3. System Metrics Monitoring: Tools like Prometheus and Grafana can be used to visualize system metrics such as CPU, memory, disk, and network usage, and to detect anomalies. For simpler setups, htop, netdata, or custom scripts can also be useful.

  4. Security Monitoring (Auditd): The Linux auditd system is a powerful tool for monitoring security events at the kernel level. It can record file access, privilege escalations, and other critical system calls. These records are invaluable for forensic analysis.

    # Example of adding an audit rule for a critical file
    sudo auditctl -w /etc/passwd -p wa -k passwd_changes
    # Query events related to this key from the audit.log file
    sudo ausearch -k passwd_changes
    

These steps increase your system's visibility, allowing you to respond to security events more quickly and effectively. The concept of observability forms the basis of understanding your systems with this triad (metrics, logs, traces).

5. Data Integrity and Backup Neglect

Simply taking backups is not enough; verifying the integrity of those backups and having the ability to restore them in case of a disaster are indispensable parts of self-hosting security. Many people take backups, but they don't regularly test these backups or plan their backup strategies according to potential disaster scenarios.

Data integrity refers to data being accurate, complete, and protected from unauthorized changes. Backup is a critical security control that ensures systems and data can be restored in case of data loss.

Why It's Important

When a system is attacked, suffers a hardware failure, or data loss occurs due to user error, robust and reliable backups play a crucial role in recovery. However, if the backups are corrupted, incomplete, or the restore procedure is unknown, the backup has no value. In many cases, taking backups is considered sufficient, while restore tests are neglected, leading to unpleasant surprises during a real disaster.

Situations like WAL bloat in database systems like PostgreSQL can cause disk space to fill up rapidly and disrupt backup processes. It's important to anticipate such scenarios and adjust backup strategies accordingly. The choice between logical (pg_dump) and physical (pg_basebackup) replication strategies has been decisive in terms of recovery time and data loss tolerance.

How to Implement

The following steps should be followed to implement effective data integrity and backup practices:

  1. Regular and Automated Backups: Back up your data automatically at regular intervals (daily, weekly). cron jobs or systemd timers can be used to achieve this automation.
  2. Off-site Backups: Store your backups in a location physically separate from your main system. This ensures your data is safe in case of fire, flood, or other disasters at the data center where the main system is located. Cloud storage services or external disks can be used.
  3. Backup Testing: At least periodically (monthly or quarterly), restore your backups in a test environment to verify that they are working and that the data integrity is maintained. This will prevent you from panicking during a real disaster.
  4. Data Integrity Checks: Use methods like checksums to verify the integrity of backed-up data. You can ensure that the data has not changed after backup by obtaining hash values of files using tools like sha256sum.

    # Simple rsync command to back up a directory to another location
    rsync -avz --delete /var/www/my-app/ /mnt/backups/my-app/
    

    ⚠️ Caution with rsync --delete

    The rsync -avz --delete command will completely synchronize the destination directory with the source directory, meaning it will delete files from the destination that are not present in the source. Therefore, ensure that the source and destination directories are correct and that no files you don't want deleted are missing from the source before running the command. Incorrect usage can lead to data loss.

    # Taking a PostgreSQL database backup
    pg_dump -Fc -Z 9 mydatabase > /mnt/backups/mydatabase_$(date +%Y%m%d).bak
    
    # Getting the hash to check the integrity of the backup file
    sha256sum /mnt/backups/mydatabase_$(date +%Y%m%d).bak > /mnt/backups/mydatabase_$(date +%Y%m%d).bak.sha256
    
  5. Disaster Recovery Plan: Create a written recovery plan that outlines the steps to be followed in case of a disaster. This plan ensures that systems and data are restored quickly and accurately. Database-specific approaches like read replica routing and partition strategies should also be part of this plan.

⚠️ WAL Bloat and Performance Regressions

If VACUUM operations are not performed regularly or are misconfigured in PostgreSQL, WAL bloat can occur. This not only increases disk usage but can also lead to performance regressions in the database. Therefore, special attention should be paid to database maintenance and WAL (Write-Ahead Log) configuration.

Conclusion

The self-hosting experience offers freedom and control, but it also brings significant security responsibilities. The 5 security practices discussed in this post – patch management, network segmentation, strong authentication, effective logging, and reliable backups – are just starting points. Each is a critical step that must be taken to make your systems more resilient against cyber threats.

Security is not a one-time project but a process that requires continuous attention and improvement. By applying these practices to your own self-hosting setups, you can keep yourself and your data safer. Remember, the best security is achieved through a proactive and layered approach.

Official Resources

Top comments (0)