# How to secure a new Linux server in 15 minutes

> How to secure a new Linux server or VPS: updates, a non-root user, SSH keys, a firewall, fail2ban and automatic security patches, with every command.

Source: https://lowcostserv.com/guides/secure-a-new-linux-server · Publisher: LowCostServ (lowcostserv.com) · Prices in US dollars, as published on November 26, 2026.

The first steps on any fresh server: updates, a non-root user, SSH keys, a firewall and automatic security patches.

By LowCostServ · Updated November 12, 2026 · 4 min read

A new server is scanned by bots within minutes of going online. None of that is personal, and none of it matters if you do six things before installing your software. The commands below are for Ubuntu and Debian; the differences for AlmaLinux and Rocky Linux are noted at the end.

## 1. Update everything

```
apt update && apt upgrade -y
```

Images are built on a given day; fixes have been released since. If the kernel was updated, reboot once with `reboot` and log back in.

## 2. Create a normal user

Working as root means every typo runs with full power. Create an account for daily use and give it `sudo`:

```
apt install -y sudo
adduser deploy
usermod -aG sudo deploy
```

No SSH key on this server yet? Set one up first: [How to connect to a Linux server with SSH](https://lowcostserv.com/guides/connect-to-a-server-with-ssh). Then copy your key to the new user, so you can log in as that user directly:

```
cp -r ~/.ssh /home/deploy/
chown -R deploy:deploy /home/deploy/.ssh
```

## 3. Lock down SSH

Open a second terminal and check that `ssh deploy@203.0.113.10` logs you in with your key, without asking for a password. If it asks for one, the key was not copied: fix that first, because the next command turns passwords off. Then, on the server:

```
cat > /etc/ssh/sshd_config.d/10-hardening.conf <<'EOF'
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
EOF
sshd -t && systemctl restart ssh
```

Root can no longer log in from outside and passwords are no longer accepted. You log in as `deploy` with your key and use `sudo` when needed.

**Do not close your original session** until the new login works. It is your way back in if a line was mistyped.

Check what is in force: `sshd -T | grep -Ei 'permitrootlogin|passwordauthentication'` must answer `no` twice. If a line still says `yes`, another file of `/etc/ssh/sshd_config.d/` is read before yours, and the first value wins: give yours a name that sorts first, such as `00-hardening.conf`, and restart the service again.

The rest of this guide is run as root: keep using the session you already have open, or type `sudo` in front of each command when you work as `deploy`.

## 4. Turn on a firewall

Allow what you use, refuse the rest:

```
apt install -y ufw
ufw default deny incoming
ufw default allow outgoing
ufw allow OpenSSH
ufw enable
```

Running a website? Add `ufw allow 80,443/tcp`. Check the result at any time with `ufw status`.

## 5. Install security updates automatically

```
apt install -y unattended-upgrades
dpkg-reconfigure -plow unattended-upgrades
```

Answer “Yes”. Security patches are now applied daily without you. Major upgrades stay manual.

## 6. Slow down the guessers

With passwords disabled, brute-force attempts cannot succeed, but they still fill your logs. Fail2ban blocks addresses that keep trying:

```
apt install -y fail2ban python3-systemd
printf '[sshd]\nenabled = true\nbackend = systemd\n' > /etc/fail2ban/jail.local
systemctl restart fail2ban
```

The second line makes it read SSH attempts from the system journal, which works on every current Debian and Ubuntu release, with or without a log file. See what it is doing with `fail2ban-client status sshd`.

## Check your work

List everything that listens for connections:

```
ss -tulpn
```

Each line is a door. If you do not recognize a service, find out what it is; if you do not need it, stop it. A database, in particular, should listen on `127.0.0.1` unless other machines must reach it.

## And the thing nobody does until too late

None of the above protects you from deleting the wrong directory. Decide today where a second copy of your data lives: another server, a storage machine, anywhere that is not this disk. Tools such as `restic` or `borg` make encrypted, incremental backups to a remote host with one scheduled command.

## AlmaLinux and Rocky Linux

The six steps are the same. These commands replace the ones above.

**Steps 1 and 2:** update, a password for the new user, and the group that gives `sudo`. Here `adduser` creates the account without asking for a password, and `sudo` will ask for one: set it now, or once SSH is locked down `deploy` will be able to log in and unable to become root.

```
dnf upgrade -y
adduser deploy
passwd deploy
usermod -aG wheel deploy
```

**Step 3:** the SSH service has another name.

```
sshd -t && systemctl restart sshd
```

**Step 4:** the firewall. SSH stays allowed; the second line is for a website.

```
dnf install -y firewalld && systemctl enable --now firewalld
firewall-cmd --permanent --add-service=http --add-service=https && firewall-cmd --reload
```

**Step 5:** automatic updates. The timer whose name ends in `-install` applies them; the plain one only downloads them.

```
dnf install -y dnf-automatic && systemctl enable --now dnf-automatic-install.timer
```

**Step 6:** Fail2ban comes from the EPEL repository, and no jail is on by default.

```
dnf install -y epel-release && dnf install -y fail2ban
printf '[sshd]\nenabled = true\n' > /etc/fail2ban/jail.local
systemctl enable --now fail2ban
```

## The checklist

- System updated, and updating itself.
- A normal user with sudo; root login disabled.
- Key-only SSH.
- Firewall on, with only the ports you use.
- Fail2ban watching SSH.
- A backup destination chosen.

## Sources and further reading

- [OpenBSD manual: sshd_config(5)](https://man.openbsd.org/sshd_config)
- [Ubuntu Server documentation: Firewall](https://ubuntu.com/server/docs/how-to/security/firewalls/)
- [Ubuntu Server documentation: Automatic updates](https://ubuntu.com/server/docs/how-to/software/automatic-updates/)
- [Fail2ban wiki: Proper fail2ban configuration](https://github.com/fail2ban/fail2ban/wiki/Proper-fail2ban-configuration)

**Put it into practice**

- [**Cloud VPS**: Cloud VPS from $3.99/mo with an unmetered 1 Gbps port.](https://lowcostserv.com/vps)
- [**Dedicated servers**: Whole Ryzen and EPYC machines from $59/mo.](https://lowcostserv.com/dedicated-servers)

**Keep reading**

- [**Your access key: an account with no email or password**: Getting started · 4 min read](https://lowcostserv.com/guides/access-key)
- [**How to connect to a Linux server with SSH**: Getting started · 3 min read](https://lowcostserv.com/guides/connect-to-a-server-with-ssh)
- [**How to connect to a Windows RDP server**: Getting started · 3 min read](https://lowcostserv.com/guides/connect-to-windows-rdp)

## Read next Two guides to follow this one.

[All security guides](https://lowcostserv.com/guides/topic/security)

- [How to set up your own WireGuard VPN on a VPS](https://lowcostserv.com/guides/set-up-wireguard-vpn): Build a private VPN on a small VPS: server and client keys, routing, firewall rules and a phone profile. (Security, 3 min read, Nov 12, 2026)
- [DMCA takedowns explained, and what DMCA-ignored hosting means](https://lowcostserv.com/guides/dmca-takedowns-explained): How a DMCA notice works, why hosts suspend first and ask later, and what “DMCA-ignored” hosting does and does not cover. (Privacy and policy, 4 min read, Nov 12, 2026)

## Your own server, in a few minutes.

Cloud VPS from $3.99 a month: no email, no ID, crypto payment, root access in minutes.

- **No KYC**: No email, no ID
- **No DMCA**: Notices not acted on
- **Crypto friendly**: BTC, ETH, XMR, USDT, SOL
- **Unmetered**: On every plan

---

LowCostServ rents cloud VPS, dedicated servers, GPU servers and Windows RDP servers and registers domain names, with no identity check and payment in crypto. Every plan and price: https://lowcostserv.com/pricing.md · The company in facts: https://lowcostserv.com/about.md · Index of the site for language models: https://lowcostserv.com/llms.txt
