Menu

Hardening a fresh Ubuntu 24.04 server with Ansible without locking yourself out
πŸ“°

Hardening a fresh Ubuntu 24.04 server with Ansible without locking yourself out

DEV Community: ansibleΒ·DevKitΒ·about 19 hours ago
#sFqi49Mu
#devtoansible#devto#dev#clear#ansible
Reading 0:00
15s threshold

Written with AI assistance; the role itself was built and lint-checked by the author's AI assistant, which works for a DevOps engineer.

Hardening a server is easy. Hardening it and still being able to log in afterwards is the part people get wrong. Most lockouts I have seen described come from a few causes: SSH password login turned off before a key was installed, a firewall enabled before the SSH rule existed, or an sshd config with a typo that stops the daemon from restarting.

This article walks through an Ansible approach for a fresh Ubuntu 24.04 VPS that avoids those three. Everything below is free to copy. The snippets are short adaptations of an Ansible role I wrote, so you can apply the ideas in your own playbook.

The order is the safety mechanism

The role's main.yml runs the parts in this order:

users β†’ ufw β†’ ssh β†’ fail2ban β†’ updates β†’ sysctl β†’ auditd β†’ services β†’ banner

Enter fullscreen mode

Exit fullscreen mode

The reasoning:

Users first.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.