Back to all posts
DevOpsLinuxDokployDockerSecurityVPSContabo

From Raw VPS to Production: Setting Up a Secure Linux Server and Installing Dokploy

October 27, 20267 min read
From Raw VPS to Production: Setting Up a Secure Linux Server and Installing Dokploy

From Raw VPS to Production: Setting Up a Secure Linux Server and Installing Dokploy

Managed cloud platforms like Vercel, Render, and Railway are fantastic when you want to deploy an app with zero infrastructure overhead. But as your projects multiply, resource limits kick in, database costs scale up, and the hosting bills can quickly become unsustainable.

That is why self-hosting on a Virtual Private Server (VPS) with modern PaaS tools like Dokploy has become such a compelling option. For as little as $5 to $10 a month on budget-friendly providers like Contabo, Hetzner, DigitalOcean, or Linode, you can run multiple full-stack apps, databases, and cron workers on your own server with generous CPU and RAM allocations.

However, moving to a bare VPS comes with a critical trade-off: you are now the sysadmin.

When your hosting provider (such as Contabo) emails you an IP address and a root password, your server is immediately exposed to the public internet. Automated bots start scanning port 22 within minutes. If you do not properly secure your server before deploying apps, you are building on a fragile foundation.

In this guide, I will walk you through the exact, battle-tested journey of provisioning a raw Linux VPS:

  1. Hardening SSH access and setting up a dedicated non-root sudo user
  2. Understanding password vs. SSH key authentication
  3. Configuring a UFW firewall without locking yourself out
  4. Installing Dokploy as a modern self-hosted PaaS

Phase 1: Hardening the Linux Server

When you first purchase a VPS, you typically log in as the root superuser:

ssh root@your_server_ip

Logging in as root gives you unlimited authority to modify any file on the system. While convenient, running all operations as root is dangerous:

  • A typo in a destructive command (like rm -rf) can instantly brick your entire operating system.
  • Malicious automated bots specifically target the root username with brute-force dictionary attacks.
  • There is no audit trail or layer of confirmation for high-privilege operations.

Here is the step-by-step process to lock this down.


Step 1: Create a Dedicated Sudo User

While still logged in as root, create a new non-root user (for example, daniel):

adduser daniel

You will be prompted to set a strong password. You can hit Enter to skip the optional questions (Full Name, Room Number, etc.).

Next, grant this new user administrative permissions by adding it to the sudo group:

usermod -aG sudo daniel

Now, daniel can execute administrative commands by prepending them with sudo.


Step 2: Verify Sudo Privileges (The Lifeline Rule)

Golden Rule of Sysadmin:
Never close your original root SSH session until you have verified that your new user can log in AND successfully execute sudo commands in a separate terminal. If something is misconfigured and you close your only session, you risk getting permanently locked out of your server.

Keep your current root terminal open. Open a second terminal window on your computer and SSH in as the new user:

ssh daniel@your_server_ip

Once connected, test that sudo elevation works:

sudo whoami

The server will prompt you for the daniel user's password. If the output returns:

root

Congratulations! Your new user has verified administrative rights.


Step 3: Password vs. SSH Key Authentication — Clearing the Confusion

A common point of confusion for developers new to VPS setup is whether they are using a password or an SSH key pair.

Authentication MethodHow It WorksStrengths & Trade-offs
Password AuthenticationYou enter a secret string that the server validates against its shadow file.Easy to set up, but vulnerable to password guessing, brute-force attacks, and shoulder surfing.
SSH Key-Based AuthenticationAn asymmetric cryptographic key pair: a private key on your laptop and a public key in the server's ~/.ssh/authorized_keys.Virtually impossible to brute-force. No password needs to be sent over the wire. Best practice for production.

What if you are currently using password authentication?

If you logged into the server by typing a password at the root@your_server_ip prompt, you are using password authentication.

Many tutorials suggest running:

rsync --archive --chown=daniel:daniel ~/.ssh /home/daniel

Note: If you are using password login, this step does not apply because there are no SSH keys in ~/.ssh yet! You can safely skip it.

(Security hygiene tip: If you ever accidentally show your server's IP address or root password on a stream or in a shared screenshot, make sure to rotate the password immediately after completing the setup.)


Step 4: Disable Direct Root Login over SSH

Now that you have a functioning sudo user, you should block anyone from logging into the root account directly over SSH. This eliminates a massive surface area for automated attack bots.

Edit the SSH daemon configuration file:

sudo nano /etc/ssh/sshd_config

Look for the line that says:

PermitRootLogin yes

(If it is commented out with a #, remove the #). Change it to:

PermitRootLogin no

Save and exit nano (Ctrl + O, Enter, then Ctrl + X).

Restart the SSH service to apply the change:

sudo systemctl restart sshd

From this point on, connecting directly with ssh root@your_server_ip will be rejected. All connections must come through your non-root user.


Step 5: Install and Configure UFW (Allow SSH First!)

A firewall controls what network traffic can enter and leave your server. Uncomplicated Firewall (UFW) is the standard firewall interface on Ubuntu and Debian.

CRITICAL WARNING:
Always allow the SSH port BEFORE enabling UFW. If you enable the firewall without opening port 22 first, UFW will block all incoming connections, including your own active SSH session!

Install UFW if it isn't already installed:

sudo apt update && sudo apt install ufw -y

Explicitly permit SSH traffic:

sudo ufw allow OpenSSH

(Alternatively, run sudo ufw allow 22/tcp if OpenSSH is not recognized by your distribution).

Verify that the rule is queued before turning the firewall on:

sudo ufw status verbose

Step 6: Enable the Firewall

Once you see port 22 / OpenSSH in the rules list, enable UFW:

sudo ufw enable

UFW will display a warning:
Command may disrupt existing ssh connections. Proceed with operation (y|n)?

Type y and press Enter. Since you already allowed SSH in Step 5, your connection will remain active.

Check the active firewall status:

sudo ufw status

Output should confirm:

Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere
OpenSSH (v6)               ALLOW       Anywhere (v6)

Step 7: Log Out of Root for Good

Your server is now hardened:

  • Direct root login is disabled.
  • Administrative tasks require sudo.
  • The firewall is active with SSH allowed.

Close the original root SSH session completely:

exit

From now on, whenever you connect to your server, use your dedicated user:

ssh daniel@your_server_ip

Phase 2: Installing Dokploy

Now that our foundation is clean and secure, let's turn this VPS into a self-hosted PaaS.

Dokploy is an open-source deployment platform that gives you the convenience of Vercel or Coolify:

  • Automatic Docker Swarm orchestration
  • Built-in Traefik reverse proxy with automated Let's Encrypt SSL certificates
  • Native support for Next.js, Node.js, Python, Go, Dockerfiles, and Compose files
  • One-click databases (PostgreSQL, MySQL, Redis, MongoDB)

Installing Dokploy

As your new daniel user, run the official installation script:

curl -sSL https://dokploy.com/install.sh | sh

What happens during this install?

  1. Dokploy installs the Docker runtime and utilities if they aren't present.
  2. It initializes a Docker Swarm single-node cluster.
  3. It creates an overlay network (dokploy-network).
  4. It starts the Traefik reverse proxy container and the Dokploy web management interface.

When the script completes, it outputs the URL to access your dashboard:

Dokploy has been successfully installed!
Please navigate to http://your_server_ip:3000 to set up your account.

Open that URL in your browser, create your admin email and password, and you are ready to deploy applications.


Summary & Quick Reference

Provisioning and running a production server doesn't have to be intimidating. By following a disciplined setup sequence, you keep your infrastructure secure and predictable:

# 1. Add non-root user & grant sudo
adduser daniel
usermod -aG sudo daniel

# 2. Test in separate terminal
ssh daniel@your_server_ip
sudo whoami

# 3. Disable root login in /etc/ssh/sshd_config
# PermitRootLogin no
sudo systemctl restart sshd

# 4. Configure UFW (SSH first!)
sudo ufw allow OpenSSH
sudo ufw enable
sudo ufw status

# 5. Install Dokploy
curl -sSL https://dokploy.com/install.sh | sh

With these practices in place, you get the cost-effectiveness and raw power of your own VPS combined with the developer experience of a modern cloud platform.

Daniel Chukwudubem

Daniel Chukwudubem

Software engineer passionate about building great products.