Put a new server on a public IP address and automated scanners find it within minutes, sometimes before you have finished logging in. That is not alarming, it is simply how the internet works, and it is the reason the first hour matters. The order of the steps below is deliberate: lock down access first, then build on a safe foundation. It assumes Ubuntu or Debian, with the equivalent RPM-based commands noted where they differ.
1. Update everything first
Fresh images are often weeks or months out of date. Update before you install anything else:
apt update && apt full-upgrade -y
On AlmaLinux or Rocky Linux, use dnf upgrade -y. Reboot if the kernel changed. Do this first because you want to build on patched software, a habit that continues in our server patching best practices.
2. Create a normal administrative user
Working as root all the time is risky, because every typo has the highest possible privilege. Create a named user with sudo rights:
adduser admin
usermod -aG sudo admin
On RPM-based systems the group is wheel. Use a name that identifies the person where possible, since shared accounts make later investigation difficult.
3. Set up SSH keys and test them
Copy your public key to the new user and confirm you can log in with it from a second terminal before changing anything else:
ssh-copy-id admin@SERVER_IP
ssh admin@SERVER_IP
Keep the original session open while you test. This precaution prevents the lockout scenario we describe in our guide to SSH "Permission denied (publickey)", where a mistake leaves nobody able to get in.
4. Harden the SSH daemon
Once key login works, tighten /etc/ssh/sshd_config:
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
Validate and reload, and only then close your original session after proving a new one still works:
sshd -t && systemctl reload ssh
The service is named sshd on RPM-based systems. Moving SSH to a different port reduces log noise but is not security on its own, so treat it as optional.
5. Turn on a firewall
Allow only what the server really serves. On Ubuntu with UFW:
ufw allow OpenSSH
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable
On AlmaLinux or Rocky, use firewall-cmd with the same idea. Add a rule for any other service deliberately, and review the list occasionally. Anything that does not need to be public, such as a database port, should not be.
6. Add brute-force protection
Fail2ban watches logs and temporarily bans addresses that fail repeatedly:
apt install fail2ban -y
systemctl enable --now fail2ban
The default SSH protection is usually enough to start. It reduces noise and slows password guessing, and it is a good second layer even with passwords disabled.
7. Get time and updates on autopilot
Accurate time is essential for logs, certificates and authentication. Chrony is the standard tool:
apt install chrony -y
timedatectl
Enable automatic security updates so that routine fixes do not depend on someone remembering. On Ubuntu, install unattended-upgrades, and on AlmaLinux or Rocky, use dnf-automatic. Remember that some updates need a service restart or a reboot to take effect.
8. Set the hostname, reverse DNS and basic identity
Set a meaningful hostname and make sure the IP has a matching reverse DNS record, especially if the server will send mail. Our email setup advice in SPF, DKIM and DMARC setup depends on this.
9. Configure backups before you need them
Decide what needs saving, where copies go and how you will restore. Store backups away from the server itself, schedule them, and run a test restore. Do this now, while the server holds nothing precious and mistakes are cheap.
10. Add monitoring and write it down
Set up uptime and resource monitoring with alerts that reach a human. Record what was installed, which ports are open, which accounts exist and where backups go. A one-page note saves hours later. Our Linux server maintenance checklist carries on from here with the recurring tasks, and top 10 tips to secure your server adds further hardening.
Installing the application stack
Only after the foundation is solid should you add the web server, database, PHP and control panel. If you are building for a small business, things to remember when setting up a server for small businesses covers the planning that comes before the commands.
If you would rather start from a server that is built and secured properly, our server setup service configures the system, services, security and backups for you, and you can contact us with what you plan to run.
Start with a correctly built and secured server
We configure the operating system, services, control panel, security and production basics for your new server.



