All articles
Infra4 min read

Securing a server when you're on your own

Firewall, keys, two-factor, anti-bot checks, rate limits, an audit: the layers I added in one day, and the three real holes I found along the way.

by Vidhal Elame
#Security#Cloudflare#VPS

Under a post that went viral, someone described handing their new server to an AI, which set it up and shipped the product "in 15 minutes". Among hundreds of replies, one was a single line: "How many backdoors did it install for you?" It was mocking, but the question was fair, and it applied to me too: I also had an AI help me with my server. When you run a machine alone, nobody checks behind you. So I took a day to do it properly.

I won't share anything here that would help anyone target my machine: no address, no internal path, no identifier. I describe the principles. They are what protects you, not secrecy about the tools.

Think in layers

No single protection is perfect. The idea is to stack several, each stopping a different kind of visitor, as early as possible:

EdgeFirewallAnti-botLimitsThe appReal personFlood (DDoS)Bypass via IPForm-spam botPassword guesserCloudflareonly CloudflareTurnstile5 tries / 10 s
Each layer stops a different kind of visitor. A real person walks through all of them without noticing; the rest get stopped as early as possible.

1. The edge: Cloudflare in front of everything

All my addresses go through Cloudflare's proxy. It absorbs request floods (DDoS), filters some known bots and hides the server's real IP address. Nobody sees where the machine is.

2. The firewall: only Cloudflare may knock

Hiding the address isn't enough: an address always leaks eventually. So I closed the server's web door to everyone except Cloudflare. A bot that knew the IP and tried to bypass Cloudflare hits a closed door. I applied the same rule over IPv4 and IPv6, which is easy to forget.

It only affects what comes in. Everything the server sends out (databases, e-mail, backups) keeps working.

3. Access: keys, not passwords

  • Logging into the server works with a key only. Password login is disabled, and bots that insist get banned automatically.
  • Two-factor everywhere: the host, DNS, GitHub (which triggers every deploy), the databases, e-mail, payments, the mailbox itself. Those accounts are what attackers go after first, long before servers.
  • The admin interface is no longer visible to the public. Before its login page even shows, you need a code sent by e-mail to one of my addresses. Only two paths stay open: the one GitHub uses to announce a new push, and the one used to renew the HTTPS certificate.

4. Forms: humans only

Forms that send an e-mail (login, contact, newsletter) are a target: a bot can use them to flood inboxes in your name. Two protections:

  • Turnstile, Cloudflare's captcha. It's invisible to almost everyone and only shows a checkbox when in doubt;
  • a rate limit: past a few requests in a few seconds, the same address is blocked for a while.
!A detail that changes everything

Behind a proxy, an app often sees the proxy's address instead of the visitor's. My rate limit was therefore counting every visitor as one person: Cloudflare. You have to tell it to read the header where Cloudflare puts the real address.

The three real holes I found

This was the most useful part of the day. While adding protections, I found three real problems, all fixed since:

  1. A sign-up page left open. Right after installation, the admin interface let anyone create an account, for a few minutes. Closed immediately by the firewall, then the account was created through an SSH tunnel. Lesson: on a new server, close first, open later.
  2. A back door handed over by a library. One of my apps must only send login links to its customers. But the authentication library also exposed its own endpoint, which sent a link to any address, skipping that check. It now requires the anti-bot check. Lesson: know everything your dependencies expose, not just what you wrote.
  3. The blind rate limit, described just above.

None of them was exploited, but none would have been found without looking.

The "backdoor" audit

To answer the mocking question, I listed everything living on the server. The commands are simple, and anyone can run them on their own machine:

cat ~/.ssh/authorized_keys        # who is allowed in
grep -v nologin /etc/passwd       # which accounts can log in
ls /etc/cron.d; crontab -l        # which tasks run on their own
ss -tlnp                          # what listens on the network
docker ps                         # which apps are running
journalctl -u ssh | grep Accepted # who actually logged in

The result: two known keys (mine, and the deploy tool's), every task accounted for, every login coming from me. Nothing unknown.

✓What I take from it

An AI can set up a server in minutes. But you answer for what's online, to your customers and to the law. Understanding each layer, knowing how to check it and being able to explain it is the job. This series is my way of doing it.

A safe server is good. A server that stays up when something breaks is better. That's the last part: backups, alerts and a plan B.