← BACK TO FORUM INDEX

Ubuntu Initial Security Settings

BY | Dec 2, 2026 | Operating Systems

Ubuntu Initial Security Settings: A Beginner’s Checklist for a Fresh Server

A fresh Ubuntu install is not the same as a secure one. Most servers are compromised through simple defaults left in place: an inactive firewall, password logins open to the internet, and packages that are not needed. This is a short checklist with the commands, what each one does, and the order that reduces the chance of locking yourself out.

What Changed

Ubuntu Pro Adds Extended Security Coverage

Ubuntu Pro (free for personal use up to a set number of machines) adds expanded security updates and optional compliance features. It is not required for a basic hardened server, but it is useful if you want longer patch support on LTS releases.

UFW Is the Simple Firewall Baseline

UFW ships with Ubuntu and is easy to enable. Cloud images often leave it inactive. Turn it on and open only the ports you actually use.

Unattended Security Updates Are Common

Many recent Ubuntu images enable unattended-upgrades for security packages. Confirm it is active so patches are applied without waiting for a manual upgrade.

1. Turn On the Firewall

Check the current state

sudo ufw status verbose
If it says inactive, nothing is filtering traffic. If active, you will see the existing rules.

Allow SSH before you enable

sudo ufw allow 22/tcp comment 'SSH admin'
sudo ufw enable
Order matters. Enabling the firewall before allowing SSH is a common way to lock yourself out of a remote box. Keep a console session open while you do this.

Open only what you need

sudo ufw allow 80/tcp comment 'Web'
sudo ufw allow 443/tcp comment 'HTTPS'
sudo ufw reload
Start with SSH and the ports you actually use. Add more later only when a service needs them.

2. Automatic Security Updates

See what is available

sudo apt update
sudo apt list --upgradable
Lists packages that have newer versions. Security updates should not sit pending for weeks.

Confirm the updater is running

systemctl is-active unattended-upgrades
If it reports inactive, enable it. On most server images the package is already installed, so this is usually just a switch.
sudo systemctl enable --now unattended-upgrades

Test the update path

sudo apt upgrade -s
The -s flag is a dry run. Review the list, then run the real upgrade when you are ready.

3. Harden SSH Access

Set up a key before disabling passwords

ssh-copy-id admin@your-server
Install your public key and confirm you can log in with it. Disabling password authentication before key login works is the second most common lockout.

Lock down the SSH service

sudo nano /etc/ssh/sshd_config
Set PermitRootLogin to no, PasswordAuthentication to no, and AllowUsers to your admin account. Restart the service only after you verify the settings.

Verify before you restart

sudo sshd -t
grep -E '^(PermitRootLogin|PasswordAuthentication|AllowUsers)' /etc/ssh/sshd_config
sudo systemctl restart ssh
sshd -t checks the config for syntax errors before you commit to it. Keep the old session open until a new key-based login succeeds.

4. Add Fail2Ban

Install and start it

sudo apt install -y fail2ban
sudo systemctl enable --now fail2ban
Fail2Ban watches auth logs and temporarily blocks IPs that repeatedly fail login attempts. It is a low-cost defense against brute-force SSH.

Whitelist yourself first

sudo nano /etc/fail2ban/jail.local
Add your admin IP to ignoreip and set a reasonable bantime. Edit jail.local, not jail.conf, so package upgrades do not overwrite your changes.

See active blocks

sudo fail2ban-client status sshd
Shows how many addresses are currently banned. The default SSH filter is usually enough until you see real attack traffic.

5. Check File Permissions

Find world-writable files

sudo find / -xdev -type f -perm -0002 2>/dev/null
Lists regular files that anyone can write to. Review the output. Anything outside temporary directories usually needs tightening.

Tighten a directory

sudo chmod 750 /var/backups
Backups should not be world-readable. 750 gives the owner full control, the group read and traverse, and everyone else nothing. Test permission changes on a spare path first.

Restrict home directories

sudo chmod 700 /home/*
This keeps SSH keys and shell history private to each user. Confirm no shared scripts or web content live under home before applying it broadly.

6. Remove What You Don’t Use

Audit what is listening

sudo ss -tulpn
Every open socket is potential attack surface. Investigate services you do not recognize before removing packages.

List installed packages

apt list --installed
A server running a desktop environment, a mail server, and a database has more surface than it needs. Remove what you do not run.

Remove and clean up

sudo apt remove --purge package-name
sudo apt autoremove
–purge removes configuration files as well. autoremove clears orphaned dependencies. Purge only packages you are sure you do not need.

Official Resources

Ubuntu Server

Official server documentation, release notes, and the Pro overview.


ubuntu.com/server

UFW Documentation

Rule syntax, application profiles, and logging behaviour.


help.ubuntu.com/community/UFW

Fail2Ban Documentation

Jail configuration, filters, and how to test a rule before it bites.


help.ubuntu.com/community/Fail2ban

Questions for the Community

Do you keep a spare console open?

If you lock yourself out over SSH, a provider console is the recovery path. Have it ready before you edit sshd_config.

How do you test a permission or update change?

Dry runs and spare systems are safer than learning on a production box. What is your process?

What is your first move on a fresh install?

Keys, firewall, then SSH lockdown is a common order. Where does yours differ?

Disclaimer

This content is for educational and informational purposes only. It is not technical advice. Commands and defaults change between Ubuntu releases. Verify each step against your version, keep a console or recovery path available, back up configuration before changing it, and test on a spare machine before applying changes to production.

DISCUSSION

No replies yet. Be the first to join the discussion!

A1 AI Assistant
Call Text A1 Forum Tech News Contact Form
Cookie Settings