Hardening script for fresh Linux servers linux, bash, debian, server, script, bash-script, firstboot
These *-firstb00t.sh scripts harden Linux servers on their very first boot from a single ssh-command run by root or sudo user.
All major steps are prompted (confirm before action) in this order:
- check root + Debian compatibility (12/13), network check
- bootstrap apt:
apt-get update+ installsudo+wget(installs wget if missing) - create/verify sudo admin user
- set hostname + timezone
- install
nala(then usenalafor remaining package installs) - install baseline tools (
curl,btop) - firewall + SSH port prompt:
- choose backend: UFW or nftables
- choose SSH port
- optional keep port
22as honeypot when using custom port
- SSH hardening:
PermitRootLogin no, optionalPasswordAuthentication no,AllowUsers, SSH reload - Fail2Ban setup:
- auto-detect SSH client IP for whitelist
- prompt for extra whitelist IP/CIDRs (local/public)
- forever ban (
bantime=-1) with whitelist safety net
- optional security services:
- unattended-upgrades
- AppArmor
- rkhunter
- FTP policy prompt (skip or configure)
- optional container engine:
- Docker CE (installs
ca-certificates+gnupgonly when needed for Docker repo) - or Podman
- prompt volume root folder for bind-mounts/backup (default
/mnt/docker/volumes; Docker images stay in/var/lib/docker)
- Docker CE (installs
- add admin SSH public key (idempotent; no duplicate key lines)
- print summary + suggested
btopusage
debian-firstb00t.sh— main hardening scriptREADME.md— project overview
Run the appropriate command on your server at first boot as root.
For Debian 10, 11, 12, 13:
wget -qO- https://raw.githubusercontent.com/punkyard/firstb00t/main/debian-firstb00t.sh | bashRequirements:
- Debian 12 or 13 server with network access
- root shell or root SSH login
bashavailable (default on Debian)
- run script and answer prompts step-by-step
- duplicate the .env.sample file and pre-fill your answers to these questions and let the script run automatically