This Bash script automates the provisioning and hardening of a Debian 12 or Ubuntu server (20.04, 22.04, 24.04 LTS, or 24.10). It configures essential security settings, user management, SSH hardening, firewall rules, and optional features like Docker, Tailscale (with Headscale support), and system monitoring (SMTP and ntfy). The script is idempotent, supports configuration files for automation, and provides flexibility for missing or partial configurations.
You can provide a configuration file (e.g., `/etc/setup_harden.conf`) to automate setup. If variables are missing or invalid, the script will prompt interactively (unless in `--quiet` mode, where it skips optional settings).
- **Required Variables**: `USERNAME`, `HOSTNAME`, `SSH_PORT`. If missing, the script will prompt (non-quiet mode) or fail (quiet mode).
- **Optional Variables**: All others (e.g., `UFW_PORTS`, `SMTP_*`, `NTFY_*`, `TAILSCALE_*`). If partially provided, the script prompts for missing values or skips the feature in quiet mode.
- **Validation**: The script validates all inputs (e.g., username format, port numbers, URLs). Invalid values trigger prompts or skipping.
- **Missing Variables**: If a config file lacks variables, the script prompts interactively (non-quiet mode) or skips optional features (quiet mode).
- **Partial Configurations**: For features like Tailscale, SMTP, or ntfy, if some variables are missing, the script prompts for them or skips the feature in quiet mode.
- **No Config File**: Falls back to full interactive mode (non-quiet) or minimal setup with optional features skipped (quiet).
- **Summary**: The final summary lists applied, skipped, or prompted settings.