Secure a home Linux server against external intrusion
If you run a server at home that is accessible from outside, it can become a target for hackers at any time. This guide provides specific commands and procedures to harden server security, covering everything from SSH configuration to firewalls and intrusion detection. Instead of complex security theory, it walks you through practical steps that you can copy and run immediately to secure your server.
Why fragmented information was consolidated
There are many articles online about Linux security, but the information is often fragmented, making it difficult to grasp the full picture. Based on the author's experience setting up their own Debian server, the necessary security measures have been organized into a single flow. While it does not cover every topic, it arranges the core security steps that a home server operator needs to know in a logical order. The structure specifically accounts for the sequence of security tasks where order matters, such as configuring SSH before applying the firewall.
Key steps to protect the server
The guide begins on the local network, before the server is exposed to the internet.
- SSH key authentication Generate an Ed25519 key pair and disable password authentication to restrict access.
- Firewall configuration Use UFW to configure the system so that only allowed ports are open and all others are blocked.
- Intrusion prevention Use Fail2Ban and CrowdSec to detect and block malicious traffic in real time.
- System auditing Use Lynis and AIDE to track vulnerabilities in system settings and file changes.
Pre-start checks
This guide is not limited to a specific Linux distribution, but the author wrote it based on Debian. Therefore, if you use a different distribution, you must convert the package management commands yourself (for example, using dnf instead of apt). The guide also does not cover the Linux installation process itself, so you must already have Linux installed on the server and be able to connect remotely via SSH. Before starting, it is important to define your threat model and prepare a recovery method (such as console access or backups) in case you lose access to the server due to a configuration error.
Who this guide is for
This guide is designed for users who want to keep a server they run at home secure, rather than for complex enterprise-level security policies. Therefore, for large data centers or environments requiring advanced security, it is recommended to also refer to CIS benchmarks or official distribution documentation. Additionally, since not all commands are automatically verified, you need to develop the habit of directly checking whether settings are applied correctly at each step. While you can automate the process using Ansible playbooks, manually understanding and applying the settings can be more helpful for learning security concepts.