{"id":815,"date":"2025-01-22T18:34:51","date_gmt":"2025-01-22T18:34:51","guid":{"rendered":"https:\/\/blog.eu.enginyr.ing\/?p=815"},"modified":"2025-01-22T18:34:52","modified_gmt":"2025-01-22T18:34:52","slug":"how-to-secure-a-vanilla-vps-a-comprehensive-guide-for-linux-beginners","status":"publish","type":"post","link":"https:\/\/www.serverspan.com\/en\/blog\/how-to-secure-a-vanilla-vps-a-comprehensive-guide-for-linux-beginners\/","title":{"rendered":"How to Secure a Vanilla VPS: A Comprehensive Guide for Linux Beginners"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">A vanilla VPS is a blank slate, ideal for deploying your applications and services. However, it is critical to secure your VPS to prevent unauthorized access and vulnerabilities. This guide provides step-by-step instructions to secure a fresh installation of a Linux-based VPS, such as AlmaLinux or Alpine, catering to users with basic Linux familiarity but minimal server administration experience.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Securing Your VPS is Important<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Out-of-the-box VPS installations often come with default configurations that might expose your server to attacks. Proper security measures protect your data, applications, and overall system integrity.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step-by-Step Guide to Securing Your VPS<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. Update Your System<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Regular updates ensure you have the latest security patches.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Update on AlmaLinux or RHEL-based distributions\nsudo yum update -y\n\n# Update on Alpine Linux\nsudo apk update &amp;&amp; sudo apk upgrade\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. Create a Non-Root User<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Avoid using the root account for daily tasks to minimize the risk of accidental changes or breaches.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Add a new user\nsudo adduser username\n\n# Grant sudo privileges\nsudo usermod -aG wheel username  # For AlmaLinux\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. Disable Root Login<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Prevent direct root access via SSH to reduce attack risks.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Edit the SSH configuration file: <code>sudo nano \/etc\/ssh\/sshd_config<\/code><\/li>\n\n\n\n<li>Set: <code>PermitRootLogin no<\/code><\/li>\n\n\n\n<li>Restart SSH: <code>sudo systemctl restart sshd<\/code><\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">4. Set Up SSH Key Authentication<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Switch to SSH key-based authentication for stronger security.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Generate a key pair on your local machine: <code>ssh-keygen -t rsa -b 4096<\/code><\/li>\n\n\n\n<li>Copy the public key to your server: <code>ssh-copy-id username@your-server-ip<\/code><\/li>\n\n\n\n<li>Disable password authentication: <code>sudo nano \/etc\/ssh\/sshd_config<\/code> Update: <code>PasswordAuthentication no<\/code><\/li>\n\n\n\n<li>Restart SSH: <code>sudo systemctl restart sshd<\/code><\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">5. Change the Default SSH Port<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Changing the SSH port can reduce unauthorized login attempts.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Edit the SSH configuration: <code>sudo nano \/etc\/ssh\/sshd_config<\/code><\/li>\n\n\n\n<li>Update: <code>Port 2222<\/code><\/li>\n\n\n\n<li>Restart SSH: <code>sudo systemctl restart sshd<\/code><\/li>\n\n\n\n<li>Update your firewall to allow the new port.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">6. Enable a Firewall<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Restrict traffic to only necessary services.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">AlmaLinux (with <code>firewalld<\/code>):<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl enable firewalld\nsudo systemctl start firewalld\nsudo firewall-cmd --permanent --add-port=2222\/tcp\nsudo firewall-cmd --reload\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Alpine Linux (with <code>iptables<\/code>):<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo iptables -A INPUT -p tcp --dport 2222 -j ACCEPT\nsudo iptables-save &gt; \/etc\/iptables.rules\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">7. Install Fail2Ban<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Protect your server from brute force attacks.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Install Fail2Ban on AlmaLinux\nsudo yum install fail2ban -y\nsudo systemctl enable fail2ban\nsudo systemctl start fail2ban\n\n# Install Fail2Ban on Alpine Linux\nsudo apk add fail2ban\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">8. Close Unnecessary Ports<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Identify and block unused ports to minimize exposure:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo netstat -tuln  # List open ports\nsudo iptables -A INPUT -p tcp --dport &#91;PORT] -j DROP\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">9. Harden Network Configurations<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Secure network settings by modifying the <code>sysctl<\/code> configuration.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Edit the file: <code>sudo nano \/etc\/sysctl.conf<\/code><\/li>\n\n\n\n<li>Add: <code>net.ipv4.conf.all.rp_filter = 1 net.ipv4.conf.all.accept_source_route = 0 net.ipv4.conf.all.log_martians = 1<\/code><\/li>\n\n\n\n<li>Apply changes: <code>sudo sysctl -p<\/code><\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">10. Regularly Back Up Your Data<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Set up automated backups to secure your data against accidental loss or corruption.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use tools like <code>rsync<\/code> or <code>tar<\/code>.<\/li>\n\n\n\n<li>Schedule backups with <code>cron<\/code>.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">11. Monitor Logs<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Regularly review logs for suspicious activity:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># View authentication logs\nsudo tail -f \/var\/log\/auth.log\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">12. Use Malware Detection Tools<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Install and configure tools like ClamAV to scan for malware:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo yum install clamav -y  # For AlmaLinux\nsudo apk add clamav         # For Alpine Linux\nsudo freshclam\nsudo clamscan -r \/home\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Additional Tips<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use strong, unique passwords for all user accounts.<\/li>\n\n\n\n<li>Enable automatic updates for software and services.<\/li>\n\n\n\n<li>Disable unnecessary services or daemons.<\/li>\n\n\n\n<li>Test server accessibility after making security changes.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Learn More with ENGINYRING<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.enginyring.com\/en\/webhosting\">Web Hosting Services<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.enginyring.com\/en\/virtual-servers\">Virtual Servers (VPS)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.enginyring.com\/en\/cpanel-management\">Server Management Services<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">By implementing these steps, you can significantly improve the security of your vanilla VPS. Regular monitoring and updates ensure your system stays secure as new vulnerabilities emerge.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A vanilla VPS is a blank slate, ideal for deploying your applications and services. However, it is critical to secure your VPS to prevent unauthorized access and vulnerabilities. This guide provides step-by-step instructions to secure a fresh installation of a Linux-based VPS, such as AlmaLinux or Alpine, catering to users with basic Linux familiarity but [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":816,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,12],"tags":[4196,4195,4207,4197,3713,4199,4203,4198,4201,159,4193,4204,4206,170,4192,4202,4194,4205,4200,4191],"class_list":["post-815","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","category-virtual-servers","tag-almalinux-security-tips","tag-alpine-linux-security-setup","tag-beginner-vps-security-guide","tag-disable-root-login","tag-enginyring-vps-hosting","tag-fail2ban-configuration","tag-fail2ban-for-vps","tag-firewall-for-vps","tag-linux-security-monitoring","tag-linux-server-security","tag-linux-vps-basics","tag-malware-protection-for-vps","tag-network-hardening-linux","tag-secure-linux-server","tag-secure-vps-setup","tag-server-hardening-tips","tag-ssh-key-authentication","tag-ssh-port-change","tag-vps-backups","tag-vps-security-guide"],"_links":{"self":[{"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/815","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=815"}],"version-history":[{"count":0,"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/815\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=\/wp\/v2\/media\/816"}],"wp:attachment":[{"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=815"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=815"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=815"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}