dedicated server

How to Secure a New Linux Server in the First Hour

How to Secure a New Linux Server in the First Hour

A freshly provisioned machine is reachable from the whole internet within minutes of booting, and automated scanners start probing SSH almost immediately. The good news is that most of the risk comes from a handful of default settings, and you can close them before you install a single application.

In brief

A practical first-hour checklist for a fresh Linux server: updates, SSH keys, a default-deny firewall, fail2ban, automatic patches and a first backup.

On this page

This checklist is written for Debian, Ubuntu and RHEL-family systems, on a VPS or a dedicated server alike. Work through it in order, because each step makes the next one safer, and you finish the hour with a secure new Linux server ready for applications.

Minutes 0-10: update packages and create your own user

Log in with the credentials or key your provider gave you and bring the system up to date before anything else. On Debian or Ubuntu that means apt update followed by apt upgrade; on Rocky Linux, AlmaLinux or Fedora use dnf upgrade. If the kernel was updated, reboot now, while nothing important is running.

Next, create a regular user for daily work and give it administrative rights through sudo. Add it to the sudo group on Debian-based systems or the wheel group on RHEL-based ones. Working as root by habit means every typo runs with full privileges, and it makes logs harder to read because every action looks the same.

Minutes 10-25: switch SSH to keys and lock down root

Generate a key pair on your own computer with ssh-keygen -t ed25519, protect it with a passphrase, and copy the public key to the server with ssh-copy-id. Open a second terminal and confirm that you can log in as your new user with the key before you change anything else.

Then create an early drop-in file such as /etc/ssh/sshd_config.d/00-hardening.conf and apply three changes in it:

  • PermitRootLogin no, so nobody can log in directly as root.
  • PasswordAuthentication no, so password guessing stops being a viable attack.
  • KbdInteractiveAuthentication no, which closes the keyboard-interactive fallback that can still accept passwords.

The file name matters: sshd keeps the first value it reads for each option, and drop-ins are included at the top of the main config. Many cloud images ship 50-cloud-init.conf with PasswordAuthentication yes, which would override the main file, so keep the 00 prefix or remove that file. Check the syntax with sshd -t, reload the service, confirm the effective value with sshd -T | grep -i passwordauthentication and test a fresh login from the second terminal. A different SSH port only cuts log noise; it is not a security control.

Minutes 25-40: default-deny firewall and fail2ban

A firewall should block everything inbound except what you deliberately expose. On Ubuntu, ufw is the easiest route: allow SSH first, then HTTP and HTTPS if you plan to run a website, then enable it. On RHEL-family systems, firewalld does the same job with zones. Whatever tool you use, allow SSH before you turn the firewall on, and confirm with ss -tulpn which services are actually listening.

A network firewall in your provider's panel, if available, is a useful second layer but does not replace the host firewall.

With password logins disabled, brute force is already far less dangerous, but fail2ban still earns its place: it temporarily bans addresses that fail repeatedly, including on services you add later. The default SSH jail is a sensible start; enable it in /etc/fail2ban/jail.local rather than editing the shipped config. Debian 12 has no auth.log by default, so add backend = systemd to that jail.

Minutes 40-50: automatic security updates and correct time

Most compromises of small servers exploit vulnerabilities that already had a patch. Install unattended-upgrades on Debian or Ubuntu, or dnf-automatic on RHEL-family systems, and limit it to security updates if you prefer to review feature updates yourself. Decide how you will handle kernel updates that need a reboot, for example a short maintenance window each week.

Accurate time matters more than it seems. TLS certificates, log correlation, two-factor codes and many cluster tools break when the clock drifts. Check timedatectl, make sure NTP synchronisation is active through systemd-timesyncd or chrony, and set the timezone you want to see in your logs.

Minutes 50-60: take a first backup and write things down

Before you deploy anything, decide where backups will go and run the first one. A provider snapshot is a quick safety net for configuration mistakes, but it often lives on the same platform as the server. For real protection, copy data off the machine with a tool such as restic or borg to storage in a different location, and plan a restore test early rather than after the first incident.

Finally, write a short record of what you did: the user you created, firewall rules, open ports and where backups go. That note turns the next server setup into a repeatable routine and makes later audits much faster.

What to do after the first hour

The first hour removes the obvious openings, but security is ongoing work. Over the following days, add monitoring and alerts for disk space and failed logins, review which services really need to be public, and consider tools like auditd or a file integrity checker if your workload handles sensitive data. Later, capture the routine in an Ansible playbook or cloud-init file.