A fresh Debian server is quiet, small and ready for almost anything. It is also reachable by every scanner on the internet from the minute it boots. The first half hour decides whether the box stays boring or turns into a cleanup job.
This is the routine I run on every new Debian 12 or 13 VPS before I install a single app. Every step is plain Debian, so it works the same on any provider.
1. Log in and update everything
Your provider gives you an IP address and a root password or an SSH key. Log in:
ssh root@203.0.113.10
Then bring the package list and every installed package up to date:
apt update && apt full-upgrade -y
If the upgrade pulled in a new kernel, reboot now rather than later:
[ -f /var/run/reboot-required ] && reboot
2. Set the hostname and time zone
A clear hostname saves confusion once you run more than one server.
hostnamectl set-hostname web-01
timedatectl set-timezone UTC
I keep servers on UTC. Logs from several machines line up, and nothing shifts when daylight saving changes.
3. Create a normal user with sudo
Working as root all day means one typo can wipe the system. Make a regular user and give it sudo:
adduser deploy
usermod -aG sudo deploy
4. Copy your SSH key to the new user
From your own computer, not the server:
ssh-copy-id deploy@203.0.113.10
No key yet? Make one first with ssh-keygen -t ed25519. Then open a second terminal and confirm you can log in as deploy with the key before you touch the SSH settings. Keep the first session open as a safety net.
5. Lock down SSH
On Debian, the cleanest way to change SSH settings is a drop-in file, so package updates never overwrite your edits:
sudo nano /etc/ssh/sshd_config.d/10-hardening.conf
Put this inside:
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
Check the syntax, then restart the service:
sudo sshd -t && sudo systemctl restart ssh
Test a fresh login from another terminal before you close the old one. If something is wrong, you still have a way back in.
6. Turn on a firewall
Debian does not enable a firewall by default. UFW is the simplest option:
sudo apt install ufw -y
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow OpenSSH
sudo ufw enable
Open only what you need later, for example sudo ufw allow 80,443/tcp for a web server. Check the result with sudo ufw status verbose.
7. Add fail2ban for repeated login attempts
Key-only SSH already stops password guessing, but fail2ban keeps the logs clean and slows down noisy scanners:
sudo apt install fail2ban -y
On recent Debian releases the logs live in the systemd journal, so tell the SSH jail to read from there:
sudo nano /etc/fail2ban/jail.d/sshd.local
[sshd]
enabled = true
backend = systemd
maxretry = 5
bantime = 1h
sudo systemctl restart fail2ban
sudo fail2ban-client status sshd
8. Install security updates automatically
Security fixes should not wait for you to remember them:
sudo apt install unattended-upgrades -y
sudo dpkg-reconfigure -plow unattended-upgrades
Answer yes. Debian will now install security updates on its own every day. Kernel updates still need a reboot, so glance at /var/run/reboot-required once a week.
9. Add swap on small plans
A 1 GB or 2 GB VPS can run out of memory during a big apt run or a build. A small swap file stops the out-of-memory killer from ending your process:
sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
Lower how eagerly the kernel swaps so RAM is still used first:
echo 'vm.swappiness=10' | sudo tee /etc/sysctl.d/99-swap.conf
sudo sysctl --system
10. Install the few tools you will want anyway
sudo apt install curl wget git htop ncdu ca-certificates -y
htop shows what is using CPU and RAM. ncdu shows what is filling the disk, which is the most common reason a small server falls over.
11. Plan backups before you need them
A snapshot from your provider is good, but it lives with the same provider. Keep at least one copy somewhere else. For files and databases, restic or borg sent to object storage works well and only stores changes after the first run.
Write down how to restore, then try it once. A backup you have never restored is a guess.
A short checklist
- System updated and rebooted
- Hostname and UTC time zone set
- Regular sudo user with an SSH key
- Root login and passwords off for SSH
- UFW on with only SSH open
- fail2ban watching SSH
- Security updates installing themselves
- Swap on small plans
- Backups that leave the server, and one test restore
That is roughly twenty minutes of work, and the server is now in better shape than most machines on the internet. From here, install your web server, database or containers with a clean conscience.
If you still need a box to practise on, a small Linux VPS with Debian and full root access is enough for every step above.
Top comments (0)