This is a neat little BASH script that should be ran immediately after your VPS boots up the first time. It will help deploy most known best security practices to date. Ultimately, helping you maintain and start off with a secure environment for your VPS!
- Update system packages
- Create a new user with sudo privileges
- Set up SSH keys for the new user (prompted during setup)
- Set up a firewall using UFW to allow only inbound SSH on your configured port (default:
13337) - Disable root login and password authentication via SSH
- Install and configure Fail2Ban
- Enable automatic security updates
The SSH port is defined as a variable at the top of lock-figuration.sh:
SSH_PORT=13337Change this before running if you want a different port. It's used everywhere — UFW, sshd_config, and Fail2Ban — so you only need to change it in one place.
# Must be run as root on a fresh VPS
chmod +x lock-figuration.sh
./lock-figuration.shThe script will:
- Update and upgrade all packages
- Create a new user and add them to sudo
- Prompt you to paste your SSH public key — do this before continuing or you'll be locked out
- Configure UFW to only allow your SSH port
- Harden sshd_config (disable root login, disable password auth, set custom port)
- Install and configure Fail2Ban with a jail on your SSH port
- Enable unattended security upgrades
IMPORTANT: Test your login in a new terminal before closing your current session!
ssh -p <port> -i <private_key> user@<server_address>
Let me know if I should add anything else!