A fresh installation is only the beginning. A proper Debian 12 server setup turns a default system into a secure, manageable production machine: the package cache is updated, time is synchronized, a non-root administrator exists, SSH is protected by keys, and a default-deny firewall blocks everything you did not explicitly allow. Skipping these basics is how new servers get compromised within hours of going online.
This guide walks through the essential first configuration of a Debian 12 (Bookworm) server, in the order an experienced administrator would do it. It assumes you have just finished installing Debian 12 and can log in as root or as a user with sudo privileges.
Prerequisites for Debian 12 Server Setup
- A server or VPS running Debian 12 with network access.
- Root access, either directly or through sudo.
- A local SSH key pair on your workstation. If you do not have one yet, read how to generate SSH keys on Linux first.

Step 1: Update the System in Your Debian 12 Server Setup
Start every Debian 12 server setup by refreshing the package index and applying all available updates. This guarantees you are configuring the newest, patched versions of every tool below.
apt update && apt full-upgrade -y
If a new kernel was installed, reboot before continuing so the server runs it:
reboot
Step 2: Set the Hostname and Time Zone
A meaningful hostname makes logs and monitoring far easier to read. Set it with hostnamectl and confirm the matching entry in /etc/hosts:
hostnamectl set-hostname web-01
nano /etc/hosts
Make sure there is a line like 127.0.1.1 web-01. For a detailed walkthrough, see how to change the hostname in Linux. Next, set the time zone and confirm that NTP synchronization is active — accurate time matters for logs, TLS certificates, and scheduled jobs:
timedatectl set-timezone Asia/Ho_Chi_Minh
timedatectl
The output should report “System clock synchronized: yes” and “NTP service: active”.
Step 3: Create a Non-Root Administrator User
Working as root all day is dangerous: one typo can destroy the system, and automated attacks target the root account constantly. Create a personal administrator account instead:
adduser deploy
usermod -aG sudo deploy
Copy your SSH public key to the new account so you can log in with it:
mkdir -p /home/deploy/.ssh
cp ~/.ssh/authorized_keys /home/deploy/.ssh/authorized_keys
chown -R deploy:deploy /home/deploy/.ssh
chmod 700 /home/deploy/.ssh
chmod 600 /home/deploy/.ssh/authorized_keys
Open a second terminal and test the login as deploy before you lock anything down. Never close your only working session while changing SSH settings.
Step 4: Harden SSH Access
With key-based login working for your new user, edit /etc/ssh/sshd_config and set the following options:
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
MaxAuthTries 3
Validate the configuration and reload the service:
sshd -t && systemctl reload ssh
Note that Debian names the service ssh, not sshd. From here on, brute-force bots will find neither a root account to attack nor a password prompt to guess against. For an extra layer, you can later change the SSH port, but treat that as obscurity rather than real security.
Step 5: Enable a Default-Deny Firewall
Debian 12 ships with nftables as its native firewall framework. The simplest robust setup uses the nftables service with a small ruleset. Enable the service and add a baseline policy that drops unsolicited input while allowing SSH, HTTP, and HTTPS:
apt install -y nftables
systemctl enable nftables
Edit /etc/nftables.conf to define an inet filter table with an input chain whose policy is drop, accept traffic on the loopback interface, accept established and related connections, then accept TCP ports 22, 80, and 443. Load and verify the ruleset:
nft -c -f /etc/nftables.conf && systemctl restart nftables
nft list ruleset
Always keep your current SSH session open until you have proven that a new session can still connect through the firewall.
Step 6: Install Essential Tools
A small set of utilities makes daily administration much easier:
apt install -y curl wget git vim htop tmux ufw fail2ban unattended-upgrades
Fail2ban watches log files and temporarily bans IP addresses that repeatedly fail to log in. Enable it for SSH:
systemctl enable --now fail2ban
Many administrators also add a swap file on small VPS instances to survive memory spikes; 1–2 GB is a sensible starting point.
Step 7: Turn On Automatic Security Updates
Unpatched systems are the number one cause of server compromises. Enable unattended security updates now (our dedicated guide in this category covers every option in depth):
dpkg-reconfigure -plow unattended-upgrades
Answer “Yes” to automatically download and install stable security updates.
Troubleshooting
Locked out after changing sshd_config
Use your provider’s web console (VNC) to log in locally, fix the configuration, and run sshd -t to see the exact error line. This is why testing a second session before disconnecting matters.
sudo says the user is not in the sudoers file
Log in as root and run usermod -aG sudo youruser, then log out and back in so the new group membership takes effect.
Conclusion
Your Debian 12 server setup is complete: patched software, a named host with synchronized time, a non-root administrator, key-only SSH, a default-deny nftables firewall, fail2ban, and automatic security updates. According to the Debian Administrator’s Handbook and wiki, these baseline practices eliminate the most common attack paths against fresh servers. From here you can install a web stack, Docker, or monitoring with confidence that the foundation is solid.