{"id":1535,"date":"2025-08-07T16:43:38","date_gmt":"2025-08-07T16:43:38","guid":{"rendered":"https:\/\/blog.eu.enginyr.ing\/?p=1535"},"modified":"2025-08-07T16:43:39","modified_gmt":"2025-08-07T16:43:39","slug":"a-practical-guide-to-vps-hardening-15-essential-security-steps-for-linux-servers","status":"publish","type":"post","link":"https:\/\/www.serverspan.com\/en\/blog\/a-practical-guide-to-vps-hardening-15-essential-security-steps-for-linux-servers\/","title":{"rendered":"A Practical Guide to VPS Hardening: 15 Essential Security Steps for Linux Servers"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Deploying a new Virtual Private Server (VPS) is an exciting moment. It\u2019s a blank canvas, a powerful and private space on the internet ready for you to build your next project. However, a default Linux server installation is like a new house with factory-set locks on the doors; it\u2019s functional, but it\u2019s not truly secure. Every day, automated bots and malicious actors scan the internet for newly deployed servers, probing them for common vulnerabilities left open by default. Leaving your VPS in its initial state is an open invitation for trouble. True server security isn&#8217;t about a single, magical solution; it&#8217;s about a systematic process of building layers of defense. This is known as &#8220;server hardening.&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This comprehensive guide is designed to be your go-to Linux server security checklist. We will walk you through 15 essential steps to transform your new, vulnerable VPS into a hardened, resilient fortress. These practices are the foundation of professional system administration and are critical for protecting your data, applications, and reputation. Whether you are a beginner launching your first WordPress site or an experienced developer setting up a complex application, following this guide will dramatically improve your server&#8217;s security posture. We will cover everything from basic user management and firewall configuration to automated updates and intrusion detection, providing clear explanations and the exact commands you need to execute along the way.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The 15-Step VPS Hardening Checklist<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before you begin, ensure you are logged into your server as the root user. These initial steps are best performed with root privileges before we lock that account down.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Update Your System Software<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The very first step on any new server is to ensure all installed software is up to date. The operating system image your provider uses might be several weeks or months old, meaning it could be missing critical security patches. Running an update and upgrade ensures you are starting from a secure, current baseline.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><b>For Debian\/Ubuntu Systems:<\/b><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt update &amp;&amp; apt upgrade -y<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><b>For CentOS\/AlmaLinux\/Rocky Linux Systems:<\/b><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dnf update -y<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Create a New User with Sudo Privileges<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Operating as the root user continuously is dangerous. A single mistake or typo can have catastrophic consequences. The best practice is to create a new, non-root user for your daily tasks and grant it &#8216;sudo&#8217; privileges, which allows it to perform administrative actions when needed by prefixing commands with <code>sudo<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Create the new user (replace 'youruser' with your desired username)\nadduser youruser\n\n# Add the user to the 'sudo' group (Debian\/Ubuntu) or 'wheel' group (CentOS\/AlmaLinux)\n# For Debian\/Ubuntu:\nusermod -aG sudo youruser\n\n# For CentOS\/AlmaLinux:\nusermod -aG wheel youruser<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Configure SSH Key Authentication<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Password-based authentication is vulnerable to brute-force attacks. SSH key authentication is a far more secure method. It uses a pair of cryptographic keys: a private key that you keep on your local computer and a public key that you place on the server. The server will only allow connections from someone who possesses the corresponding private key.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First, from your <b>local computer<\/b>, generate an SSH key pair if you don&#8217;t have one:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ssh-keygen -t rsa -b 4096<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Next, copy the public key to your new user on the server (replace &#8216;youruser&#8217; and &#8216;your_server_ip&#8217;):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ssh-copy-id youruser@your_server_ip<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now you can log in to your server as the new user without a password.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4: Disable Root Login and Password Authentication via SSH<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Now that you have a sudo user with SSH key access, you should disable direct root login and password-based authentication entirely. This significantly reduces the attack surface of your server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Open the SSH configuration file with a text editor:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/ssh\/sshd_config<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Find and change the following lines. You may need to uncomment them (remove the #) and change &#8216;yes&#8217; to &#8216;no&#8217;.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PermitRootLogin no\nPasswordAuthentication no\nPubkeyAuthentication yes\nChallengeResponseAuthentication no<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Save the file and restart the SSH service to apply the changes:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart sshd<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 5: Change the Default SSH Port<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Automated bots scan for open SSH ports on the default port 22. While this is security through obscurity, changing the port can significantly reduce the number of automated login attempts logged on your server. Choose a port number between 1024 and 65535.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the same <code>\/etc\/ssh\/sshd_config<\/code> file, find the line <code>#Port 22<\/code>. Uncomment it and change 22 to your chosen port (e.g., <code>Port 2255<\/code>). Save the file and restart SSH again.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><b>Important:<\/b> Before you log out, make sure you update your firewall to allow the new port! You will also need to specify the new port when you connect in the future: <code>ssh -p 2255 youruser@your_server_ip<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 6: Set Up a Basic Firewall with UFW<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A firewall is a non-negotiable security layer. It controls incoming and outgoing network traffic. UFW (Uncomplicated Firewall) is a user-friendly front-end for managing firewall rules on Linux.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First, set the default policies to deny all incoming traffic and allow all outgoing traffic:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw default deny incoming\nsudo ufw default allow outgoing<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 7: Configure Essential UFW Rules<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">With the defaults set, you now need to explicitly allow traffic for the services you need. At a minimum, this will be SSH, HTTP, and HTTPS.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Allow your new SSH port (replace 2255 with your chosen port)\nsudo ufw allow 2255\/tcp\n\n# Allow standard web traffic\nsudo ufw allow http\nsudo ufw allow https\n\n# Enable the firewall\nsudo ufw enable<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The firewall will now be active and will persist through reboots.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 8: Install and Configure Fail2ban<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Fail2ban is an intrusion prevention software framework that protects computer servers from brute-force attacks. It scans log files and bans IP addresses that show malicious signs, such as too many password failures.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># For Debian\/Ubuntu:\nsudo apt install fail2ban -y\n\n# For CentOS\/AlmaLinux (requires EPEL repository):\nsudo dnf install epel-release -y\nsudo dnf install fail2ban -y\n\n# Start and enable the service\nsudo systemctl start fail2ban\nsudo systemctl enable fail2ban<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Fail2ban works out of the box to protect SSH, but it can be configured to protect many other services.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 9: Remove Unnecessary Network Services<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Every service listening on a network port is a potential entry point for an attacker. A core principle of server hardening is to minimize the attack surface by removing any software that is not absolutely necessary for the server&#8217;s function. Use a tool like <code>ss<\/code> or <code>netstat<\/code> to see what services are listening.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ss -tuln<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If you see services you don&#8217;t recognize or need, find the package name and remove it using your system&#8217;s package manager.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 10: Set Up Automatic Security Updates<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Manually running updates is good, but automating the process for security patches ensures that your server is protected against newly discovered vulnerabilities as quickly as possible, without requiring your intervention.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><b>For Debian\/Ubuntu:<\/b><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install unattended-upgrades -y\nsudo dpkg-reconfigure -plow unattended-upgrades<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><b>For CentOS\/AlmaLinux:<\/b><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf install dnf-automatic -y\nsudo systemctl enable --now dnf-automatic.timer<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 11: Secure Shared Memory<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>\/run\/shm<\/code> directory is used for shared memory. By default, it&#8217;s often mounted as world-writable, which can be exploited by attackers in certain scenarios. You can harden it by editing your file systems table (fstab).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/fstab<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Add the following line to the end of the file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tmpfs \/run\/shm tmpfs defaults,noexec,nosuid 0 0<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Save the file and reboot the server for the change to take effect.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 12: Install an Intrusion Detection System (IDS)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">While Fail2ban is great for blocking known brute-force attacks, a modern IDS like CrowdSec provides a more advanced, collaborative layer of defense. CrowdSec identifies aggressive behavior and shares the attacking IP&#8217;s information with a global network, proactively blocking threats identified by other users.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 13: Disable Unused Filesystems<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To further reduce the attack surface, you can prevent the kernel from loading filesystems that you don&#8217;t use (like cramfs, freevxfs, jffs2, hfs, hfsplus, squashfs, udf). This is an advanced step but adds another layer of hardening.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Create a new config file\nsudo nano \/etc\/modprobe.d\/uncommon-fs.conf\n\n# Add these lines\ninstall cramfs \/bin\/true\ninstall freevxfs \/bin\/true\ninstall jffs2 \/bin\/true\ninstall hfs \/bin\/true\ninstall hfsplus \/bin\/true\ninstall squashfs \/bin\/true\ninstall udf \/bin\/true<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 14: Implement a Regular Backup Strategy<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Security is also about recovery. Even the most hardened server can fall victim to a zero-day exploit or a configuration error. A reliable, automated, and regularly tested backup strategy is your ultimate safety net. Ensure your backups are stored off-server in a secure, geographically separate location.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 15: Conduct Regular Security Audits<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Security is not a one-time setup; it&#8217;s an ongoing process. Schedule regular audits of your server. Use tools like <code>lynis<\/code> or <code>rkhunter<\/code> to scan for common vulnerabilities, review your firewall rules, check user permissions, and analyze logs for any suspicious activity. Staying vigilant is the key to long-term security.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion: Security as a Continuous Process<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">By completing this 15-step checklist, you have transformed your default server installation from a soft target into a hardened, secure environment. You have established multiple layers of defense that will protect you from the vast majority of automated and opportunistic attacks. Remember that server security is a continuous process of vigilance, maintenance, and adaptation. New threats emerge, and software vulnerabilities are discovered daily, which is why automated updates and regular audits are so critical.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">At ENGINYRING, we build our <a href=\"https:\/\/www.enginyring.com\/en\/virtual-servers\">virtual server<\/a> offerings with security as a top priority, providing a robust foundation for you to build upon. If you prefer to focus on your business and leave the complexities of server management and hardening to the experts, our managed services team is here to help. <a href=\"https:\/\/www.enginyring.com\/en\/contact\">Contact us today<\/a> to learn how we can provide a fully secured and optimized hosting environment for your projects.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Deploying a new Virtual Private Server (VPS) is an exciting moment. It\u2019s a blank canvas, a powerful and private space on the internet ready for you to build your next project. However, a default Linux server installation is like a new house with factory-set locks on the doors; it\u2019s functional, but it\u2019s not truly secure. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1536,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,12],"tags":[9444,9448,9440,9450,4197,6004,9439,9437,9447,9441,9443,9451,9445,9454,9434,9457,9455,9456,8898,170,9460,4192,8903,9449,9452,9446,4194,4205,9458,9442,9436,9459,9453,9435,9438],"class_list":["post-1535","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","category-virtual-servers","tag-almalinux-security","tag-automated-security-updates","tag-centos-server-security","tag-crowdsec-vs-fail2ban","tag-disable-root-login","tag-enginyring-vps","tag-essential-server-security","tag-fail2ban-setup","tag-firewall-configuration-linux","tag-how-to-secure-a-vps","tag-initial-server-setup","tag-intrusion-detection-system","tag-linux-security-guide","tag-linux-server-checklist","tag-linux-server-security-checklist","tag-linux-system-hardening","tag-managed-server-security","tag-new-server-setup","tag-protect-vps-from-hackers","tag-secure-linux-server","tag-secure-shared-memory","tag-secure-vps-setup","tag-secure-web-server","tag-server-administration-basics","tag-server-security-audit","tag-ssh-hardening","tag-ssh-key-authentication","tag-ssh-port-change","tag-sudo-user-setup","tag-ubuntu-server-hardening","tag-ufw-firewall-rules","tag-ufw-tutorial","tag-vps-backup-strategy","tag-vps-hardening-guide","tag-vps-security-best-practices"],"_links":{"self":[{"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1535","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1535"}],"version-history":[{"count":1,"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1535\/revisions"}],"predecessor-version":[{"id":1537,"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1535\/revisions\/1537"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=\/wp\/v2\/media\/1536"}],"wp:attachment":[{"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1535"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1535"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1535"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}