Before you start
- SSH into your server as root.
- Keep the VNC console in mind: if an SSH or firewall step goes wrong, it still lets you log in.
- Commands are shown as root. Once you switch to your new user (step 2), put
sudoin front of them.
1. Update all packages
- Ubuntu / Debian
- AlmaLinux / Rocky
reboot. On Ubuntu, the file /var/run/reboot-required exists when a reboot is needed; on AlmaLinux and Rocky, sudo dnf needs-restarting -r tells you. More in how to update Linux packages.
2. Create a user with sudo
Working as root all the time is risky: one typo can damage the system. Create a normal user and give it admin rights throughsudo.
- Ubuntu / Debian
- AlmaLinux / Rocky
alex and run sudo whoami; it should print root. Details in create a sudo user.
3. Log in with an SSH key
On your own computer, create a key and copy it to the new user:4. Disable SSH password login
Once the key works, stop SSH accepting passwords:sshd instead of ssh in the restart command on AlmaLinux and Rocky Linux. Full explanation and checks: disable SSH password login. You can also stop root logging in over SSH.
5. Turn on a firewall
A firewall decides which network connections reach your server. Allow SSH before you enable it.- Ubuntu / Debian (UFW)
- AlmaLinux / Rocky (firewalld)
sudo ufw allow 2222/tcp.80 and 443 for a website). Guides: UFW, firewalld.
6. Enable automatic security updates
- Ubuntu / Debian
- AlmaLinux / Rocky
Ubuntu Server ships with Test without changing anything:
unattended-upgrades and installs security updates automatically. On Debian, install and switch it on:sudo unattended-upgrade --dry-run -v.7. Set the timezone and hostname
timedatectl list-timezones shows every zone name. Correct time matters for logs, cron jobs and TLS certificates. See timezone and time sync and change the hostname. To show a proper name in reverse DNS, also set reverse DNS for your IP.
8. Block repeated login attempts
Even with passwords off, bots keep knocking. Fail2ban reads your logs and bans IPs that fail repeatedly:9. Set up backups
Decide now how you would recover from a mistake or a disk failure:- On a VPS, schedule panel backups.
- Keep a second copy of important data off the server, for example with restic or rclone.
10. Check what is listening
List every service that accepts network connections:22) and possibly a local DNS resolver on 127.0.0.53. Anything you don’t recognise, look up before opening it in the firewall. See check open ports.
How to check it worked
From your computer:ssh alex@203.0.113.10logs in with your key, no password asked.ssh -o PubkeyAuthentication=no alex@203.0.113.10is refused withPermission denied (publickey).- On the server,
sudo ufw status(orsudo firewall-cmd --list-all) shows only the ports you meant to open.
Frequently asked questions
Do I need to do all ten steps?
Steps 1 to 6 and 9 are essential for any internet-facing server. Steps 7, 8 and 10 take a few minutes and save trouble later.Should I change the SSH port too?
It is optional. It reduces log noise but doesn’t replace keys and a firewall. See change the SSH port.I locked myself out during these steps. What now?
Open the VNC console, log in with the root password and undo the last change (for exampleufw allow OpenSSH or delete the file in /etc/ssh/sshd_config.d/). If you don’t know the root password, reset it.
What should I install next?
That depends on your project: a LEMP stack for websites, Docker for containers, or a game server.Related guides
VPS and dedicated server guides
Every guide in this section.
Linux security checklist
The full hardening list.
Create and use SSH keys
Step 3 in detail.
Set up UFW
Step 5 in detail.
Essential Linux commands
The basics.
Checked against the official Ubuntu Server documentation, Red Hat: Automating software updates and the OpenSSH manual on 4 November 2026; the SSH key,
sshd_config.d and UFW (dry run) steps were tested on Ubuntu 24.04 LTS. Service restarts, timedatectl and the AlmaLinux steps were not tested.Need Extra Help?
If you encounter any issues, our support team is ready to assist:- Live Chat: Quick assistance via our website.
- Support Ticket: Open a Ticket
- Discord: Join our Community
- Email: support@freakhosting.com
Last Updated: November 2026