#!/bin/bash # This script takes a clean Ubuntu Server 24.04 LTS image and installs and configures # everything needed to deploy a production-ready PostgreSQL server. set -euo pipefail # --- AESTHETICS --- GREEN='\033[0;32m' ELEPHANT='\xF0\x9F\x90\x98' NC='\033[0m' # --- HELPER FUNCTIONS --- log() { echo -e "${GREEN}${ELEPHANT} $1${NC}" } # --- SECURITY FUNCTIONS --- configure_firewall() { log "Configuring the firewall with ufw..." sudo apt-get install -y ufw sudo ufw default deny incoming sudo ufw default allow outgoing sudo ufw allow ssh sudo ufw allow 5432/tcp # PostgreSQL port echo "y" | sudo ufw enable } harden_ssh() { log "Hardening SSH configuration..." sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak sudo tee /etc/ssh/sshd_config > /dev/null < /dev/null <