Skip to content

Production Ready VPS in Minutes

Published: at 03:22 PMSuggest Changes

When deploying a Virtual Private Server (VPS) for production use, security should be your top priority. A freshly provisioned server comes with default configurations that prioritize accessibility over security—fine for development, but dangerous in production environments. This guide walks you through essential hardening steps that transform your VPS from vulnerable to production-ready.

Before everything else we need a VPS, for which we will be using DigitalOcean, here’s a quick tutorial on how to create a Droplet on DigitalOcean.

Now let’s get into securing and making our VPS Production ready.

1. Initial System Updates

sudo apt update && sudo apt upgrade -y
shutdown now -r

Why this matters:

Fresh server images often contain outdated packages with known vulnerabilities. The first line updates your package lists and upgrades all installed packages to their latest versions. The immediate reboot ensures any kernel updates take effect and that your server starts clean with the latest security patches.

Best practice: Always perform this step before making any configuration changes, as package updates can sometimes reset configuration files.

2. Creating a Dedicated User Account

sudo adduser <username>
sudo usermod -aG sudo <username>
su - <username>

NOTE: Change the with the username you want to add

Running administrative tasks as root violates the principle of least privilege. By creating a dedicated user account, you reduce the blast radius of potential security breaches and create an audit trail for administrative actions.

What happens here :

3. SSH Key Authentication Setup

mkdir -p ~/.ssh
chmod 700 ~/.ssh
touch ~/.ssh/authorized_keys
echo "your_public_key_here" > ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys

Password authentication is inherently weak—passwords can be brute-forced, guessed, or compromised through data breaches. SSH keys provide cryptographic authentication that’s exponentially more secure.

Directory permissions explained:

These restrictive permissions are crucial—SSH will refuse to use keys with overly permissive access.

4. SSH Hardening Configuration

sudo vi /etc/ssh/sshd_config

Critical configuration changes (sshd_config) file:

PermitRootLogin no
usePAM no  
PasswordAuthentication no

exit the file and then on your terminal

sudo systemctl restart ssh

Why this matters

Important: Test your SSH key authentication before implementing these changes. Once password authentication is disabled, key-based access becomes your only entry method.

One additional hardening measure worth considering is changing SSH from its default port 22 to a custom port. While this provides security benefits, it comes with significant operational overhead (we’re not going to cover it in this blog).

5. Streamlined SSH Access

Most of our configuration is done, but we can still make the process of connecting to our VPS a bit more smooth, see now everytime we need to connect to our VPS we have to pass the private-key, here a fix for that.

In your local machine’s terminal

vi ~/.ssh/config

SSH config file:

Host your-server-nickname
    HostName your_server_ip
    User <username>
    IdentityFile path_to_your_private_key
    IdentitiesOnly yes

NOTE: The username should be the same that we created in step 2 of this tutorial.

Benefits:

Operational benefits:

Additional Security Considerations:

While this guide covers fundamental hardening steps, consider these additional measures for enhanced security:

Key Takeaways:

This configuration establishes multiple security layers: eliminating weak authentication methods, restricting privileged access, and implementing cryptographic verification. Each step addresses specific attack vectors commonly exploited in server breaches.


Previous Post
Build your own Posthog - PART 1
Next Post
GoogleSignIn Macos - Flutter