VPS Security: How to Secure a Linux Server

This article explains how to secure a Linux server. First, keep the kernel and software updated by regularly applying security patches. Next, use strong passwords with a mix of character types and change them regularly. Then change the default SSH port to make it harder for attackers to target. After that, enable the firewall and block unused ports, allowing only the traffic your applications need. Finally, use SSH keys instead of passwords by generating a key pair, copying the public key to the server, and disabling password login and root login in the SSH configuration, restarting the service afterward.

Why You Need to Secure Linux Servers

Linux servers are widely used for hosting websites, applications, and databases. Without proper server security, your system may become an easy target for hackers. By following best practices for VPS security and cloud server security, you can greatly reduce risks and protect your server from attacks.

Steps to Secure Linux Server

Step 1: Keep Linux Kernel and Software Updated

Regular updates are the first step in server protection. Security patches fix vulnerabilities that attackers could exploit.

  • CentOS:
sudo yum update -y
  • Ubuntu / Debian:
sudo apt-get update && sudo apt-get upgrade -y

Always apply updates as soon as they are released to ensure secure Linux server performance.

Step 2: Use Strong Passwords

Passwords are the first line of server protection. Use a combination of uppercase, lowercase, numbers, and special characters. Change your passwords regularly.

To change a user password:

sudo passwd username

For detailed steps, see [How to Change Passwords for Users on Linux Server].

Step 3: Change the SSH Port

Changing the default SSH port (22) makes it harder for attackers to guess entry points.

  • Edit the SSH configuration file:
sudo vi /etc/ssh/sshd_config
  • Find the line:
#Port 22
  • Replace 22 with a custom port (e.g., 2200).
  • Restart SSH:
sudo service sshd restart

See our KB [How to Change the SSH Port] for more details.

Step 4: Enable Firewall and Block Unused Ports

Firewalls are essential for server security. They allow only trusted network traffic and block suspicious connections.

  • For CentOS (firewalld):
sudo systemctl enable firewalld
sudo systemctl start firewalld
sudo firewall-cmd --permanent --add-port=2200/tcp
sudo firewall-cmd --reload
  • For Ubuntu (ufw):
sudo ufw enable
sudo ufw allow 2200/tcp
sudo ufw status

Only open the ports required for your applications to maintain strong server protection.

Step 5: Use SSH Keys Instead of Passwords

Passwords can be brute-forced, but SSH keys provide much stronger secure server access.

  1. Generate an SSH key pair on your local machine:
ssh-keygen -t rsa -b 4096
  1. Copy the public key to your server:
ssh-copy-id user@your-server-ip
  1. Disable password login to fully enforce SSH key authentication:
sudo vi /etc/ssh/sshd_config

Update these lines:

PasswordAuthentication no

PermitRootLogin no
4. Restart the SSH service:

sudo service sshd restart

Tip: Keep two active SSH sessions open before restarting, in case of misconfiguration.

Conclusion

By applying these steps, you can significantly improve VPS security, cloud server security, and overall server protection. Keeping your Linux server secure requires continuous monitoring and updates, but it pays off by reducing risks of intrusion and ensuring data integrity.

Keywords:

secure linux, secure server, vps security, server security, cloud server security, server protection, protect server

Last Updated:   10/28/2026
Outline