PromptHub
DevOps Cybersecurity

Stop Wasting Hours on Server Setup! Use du_setup Instead

B

Bright Coding

Author

13 min read
44 views
Stop Wasting Hours on Server Setup! Use du_setup Instead

Stop Wasting Hours on Server Setup! Use du_setup Instead

How many times have you spun up a fresh VPS, stared at the terminal, and felt that sinking dread? You know the drill: create a user, harden SSH, configure the firewall, set up fail2ban, enable auto-updates, install Docker, configure backups... The checklist never ends. One missed step, and your production server becomes a crypto-mining playground for some teenager in Eastern Europe.

Here's the dirty secret nobody talks about: even senior developers copy-paste the same server setup commands from scattered notes, blog posts, and Stack Overflow threads. It's inefficient, error-prone, and frankly, embarrassing. What if I told you there's a single, battle-tested Bash script that automates this entire process with production-grade security defaults?

Meet du_setup — the open-source server hardening script that top DevOps engineers are quietly adopting. No more forgotten sshd_config tweaks. No more "oops, I left root login enabled." No more 3-hour setup marathons. In this deep dive, I'll expose exactly how du_setup works, why it's superior to manual configuration, and how you can deploy a fortress-grade server in under 15 minutes.

What is du_setup?

du_setup is a meticulously crafted Bash script created by buildplan that automates the initial configuration and security hardening of Debian and Ubuntu servers. Currently at version v0.80.6 (last updated April 30, 2026), it supports Debian 12 and 13, plus Ubuntu 20.04 through 25.04 (with newer versions marked experimental).

But du_setup isn't just another "server setup script" dumped on GitHub. It's idempotent — meaning you can run it multiple times without breaking anything. It's safety-first — backing up every critical configuration file before modification. And it's production-ready — validated through automated linting and Codacy security scans.

The project emerged from a genuine pain point: cloud providers give you a bare OS image, but securing it properly requires dozens of precise steps that most developers either skip or get wrong. du_setup bridges this gap with an interactive, guided experience that doesn't sacrifice automation for flexibility. Every choice is yours, but the sensible defaults are already locked in.

What makes du_setup genuinely trend-worthy is its comprehensive scope. Unlike tools that handle just SSH or just firewall configuration, du_setup orchestrates the entire server security lifecycle — from user creation through automated backups, VPN integration, and security auditing. It's the difference between buying a car part by part versus driving a Tesla off the lot.

Key Features That Separate du_setup from the Pack

Let's dissect what makes this script genuinely powerful:

🔒 Defense in Depth Architecture

  • Secure User Management: Creates a dedicated sudo user with proper SSH key setup, disables root SSH access entirely, and optionally deploys a customized .bashrc for enhanced terminal productivity.
  • SSH Hardening on Steroids: Configures custom ports, enforces key-based authentication exclusively, and implements rollback mechanisms if connectivity fails.
  • Firewall with Intelligence: UFW configuration with secure deny-by-default posture, but with user-defined port allowances that don't lock you out.
  • TOTP 2FA Integration: Not just "install Google Authenticator" — du_setup generates QR codes in-terminal, includes rollback procedures, and validates the setup before committing.

🛡️ Automated Threat Response

  • Fail2Ban/CrowdSec: Monitors SSH and UFW logs, automatically banning malicious IPs with configurable thresholds.
  • Kernel Hardening: Optional sysctl modifications based on CIS Benchmarks, NIST guidelines, and OWASP practices — mitigating network and memory-based attacks.
  • Unattended Security Updates: Configures automatic patching without the usual "will this break my system?" anxiety.

🔧 Operational Excellence

  • Remote Backup Automation: Full rsync over SSH with cron scheduling, ntfy/Discord notifications, and pre-flight testing. Hetzner Storage Box integration included.
  • Tailscale Mesh VPN: One-command installation with support for standard networks, custom servers, and advanced flags like --advertise-exit-node.
  • Docker & Compose: Clean installation with proper user group configuration.
  • Security Auditing: Optional Lynis system audits and debsecan vulnerability scanning with timestamped logging.

⚡ Developer Experience

  • Comprehensive Logging: Every action logged to /var/log/du_setup_*.log with detailed summary reports.
  • Configuration Backups: All modified files preserved in /root/setup_harden_backup_* with timestamps.
  • Quiet Mode: --quiet flag for CI/CD pipelines and automated provisioning.
  • Provider Cleanup: Detects and removes cloud provider bloatware (DigitalOcean agents, cloud-init, default users) to minimize attack surface.

Real-World Use Cases Where du_setup Shines

Scenario 1: The Freelance Developer Launching Client Projects

You're deploying a Laravel application for a client on DigitalOcean. The client cares about security certifications. Instead of spending 4 hours manually hardening the server (billable time you can't really charge for), you run du_setup interactively. Fifteen minutes later, you have CIS-aligned hardening, automated backups to your Hetzner Storage Box, and a security audit report to hand the client. You just turned infrastructure setup from a cost center into a competitive advantage.

Scenario 2: The Startup Building Their First Production Cluster

Your YC-backed startup just got its seed round. You need three application servers, two database replicas, and a monitoring node — all identically configured. du_setup's --quiet mode lets you bake the hardened configuration into your Packer images or cloud-init scripts. Every server emerges from provisioning with identical security posture, logged configurations, and automated update policies. Infrastructure consistency without the Terraform complexity.

Scenario 3: The Homelab Enthusiast Securing Self-Hosted Services

You're running Nextcloud, Jellyfin, and a dozen other services on a Netcup VPS. You've been meaning to set up proper backups, VPN access for remote management, and fail2ban — but it's overwhelming. du_setup's interactive mode walks you through each decision, explains the trade-offs, and validates every step. The Tailscale integration means you can ditch exposed SSH ports entirely. Enterprise-grade security for your personal cloud.

Scenario 4: The DevOps Engineer Replacing Legacy Manual Runbooks

Your company still has a Confluence page titled "Server Setup 2019" that everyone copies from. It's outdated, inconsistent, and caused a production incident last quarter when someone forgot to disable root login. Migrating to du_setup replaces tribal knowledge with version-controlled, tested automation. The SHA256 verification ensures supply chain integrity. Runbook-as-code that actually works.

Step-by-Step Installation & Setup Guide

Prerequisites

Before starting, ensure you have:

  • Fresh Debian 12/13 or Ubuntu 20.04-25.04 installation
  • Root access or sudo privileges
  • Internet connectivity for package downloads
  • Minimum 2GB free disk space
  • For backups: SSH-accessible remote server (Hetzner Storage Box uses port 23)
  • For Tailscale: Pre-auth key from login.tailscale.com/admin

Step 1: Download and Prepare

# Download the latest script directly from GitHub
wget https://raw.githubusercontent.com/buildplan/du_setup/refs/heads/main/du_setup.sh

# Make it executable
chmod +x du_setup.sh

Step 2: Verify Script Integrity (Critical!)

Never run unverified scripts with root privileges. du_setup provides SHA256 checksum verification:

Automatic verification (recommended):

# Download the official checksum file
wget https://raw.githubusercontent.com/buildplan/du_setup/refs/heads/main/du_setup.sh.sha256

# Verify — should output: du_setup.sh: OK
sha256sum -c du_setup.sh.sha256

Manual verification:

# Generate hash and compare visually
sha256sum du_setup.sh

# Or use echo for automatic comparison
echo 00cdf04cf4603c26241b64a86d8fe349e58e5b7e649227356627eae77dc038f5 du_setup.sh | sha256sum --check

Step 3: Execute the Script

Interactive mode (recommended for first use):

# Switch to root (preserves environment better than sudo for this script)
sudo su

# Run the script
./du_setup.sh

Or with environment preservation as sudo user:

sudo -E ./du_setup.sh

Automated/CI mode:

sudo -E ./du_setup.sh --quiet

⚠️ CRITICAL WARNING: The script will prompt you to verify SSH access on the new port before disabling old access methods. Open a second terminal and test your new SSH connection before proceeding! Also ensure your VPS provider's firewall allows your custom SSH port, backup server port (23 for Hetzner), and UDP 41641 for Tailscale.

Step 4: Reboot and Verify

The script will recommend a reboot. Afterward, verify your setup using the comprehensive checklist in the README — from ssh -p <custom_port> through chronyc tracking to tailscale status.

REAL Code Examples: Inside du_setup's Implementation

Let's examine actual code patterns from du_setup to understand its engineering quality.

Example 1: Secure Script Download and Execution Pattern

The README demonstrates proper supply-chain security — increasingly critical after recent xz-utils backdoor incidents:

# Download script from specific GitHub reference (not ambiguous 'main' in production)
wget https://raw.githubusercontent.com/buildplan/du_setup/refs/heads/main/du_setup.sh
chmod +x du_setup.sh

# Download companion checksum file
wget https://raw.githubusercontent.com/buildplan/du_setup/refs/heads/main/du_setup.sh.sha256

# Cryptographic verification before execution
sha256sum -c du_setup.sh.sha256
# Expected output: du_setup.sh: OK

This pattern demonstrates defense in depth: HTTPS transport security, explicit version pinning via git refs, and cryptographic integrity verification. The checksum 00cdf04cf4603c26241b64a86d8fe349e58e5b7e649227356627eae77dc038f5 is hardcoded in documentation, enabling out-of-band verification. Compare this to the dangerous curl | bash anti-pattern still prevalent in developer tutorials.

Example 2: SSH Lockout Recovery Procedure

Even with safety mechanisms, SSH lockouts happen. du_setup provides explicit recovery commands using provider console access:

# Step 1: Remove the hardened SSH configuration fragment
sudo rm /etc/ssh/sshd_config.d/99-hardening.conf

# Step 2: Find and restore the most recent backup
# ls -td sorts by time, descending; head -1 gets the newest
LATEST_BACKUP=$(ls -td /root/setup_harden_backup_* | head -1)

# Restore original sshd_config from backup
sudo cp "$LATEST_BACKUP"/sshd_config.backup_* /etc/ssh/sshd_config

# Step 3: Restart SSH service to apply restored configuration
sudo systemctl restart ssh

This recovery pattern reveals du_setup's safety-first architecture: every modified file is timestamped and preserved. The sshd_config.d approach (using a drop-in directory) rather than editing /etc/ssh/sshd_config directly enables clean removal without parsing complex files. The variable interpolation and wildcard matching show production Bash practices, not amateur scripting.

Example 3: Backup Troubleshooting and Validation

The backup system includes comprehensive diagnostic commands:

# Verify SSH key was generated correctly
sudo cat /root/.ssh/id_ed25519.pub

# Copy key to remote backup server (Hetzner uses port 23)
sudo ssh-copy-id -p <backup_port> -s <backup_user@backup_host>

# For Hetzner specifically: ensure remote .ssh directory exists
sudo ssh -p 23 <backup_user@backup_host> "mkdir -p ~/.ssh && chmod 700 ~/.ssh"

# Test the backup script manually before relying on cron
sudo /root/run_backup.sh

# Examine detailed execution logs
sudo less /var/log/backup_rsync.log

# Verify cron job was installed correctly
sudo crontab -l
# Expected: 5 3 * * * /root/run_backup.sh #-*- managed by setup_harden script -*-

This example showcases operational maturity: Ed25519 keys for modern cryptography, explicit port handling for non-standard SSH ports, idempotent remote directory creation, manual testing before automation, and self-documenting cron comments. The less pager for log examination and structured log paths (/var/log/backup_rsync.log) follow Linux filesystem hierarchy standards.

Example 4: Tailscale Verification Commands

For VPN connectivity validation:

# Basic connectivity check
tailscale status

# Verify which control server you're connected to (standard vs. custom)
tailscale status --json | grep ControlURL

# Test Tailscale's built-in SSH (if --ssh flag was used)
tailscale ssh <username>@<tailscale-ip>

# Examine service logs for debugging
sudo journalctl -u tailscaled

The JSON output parsing with grep enables quick verification without dependencies, while journalctl integration shows systemd-native logging practices.

Advanced Usage & Best Practices

For Production Deployments:

  • Always run --cleanup-preview first on cloud VPS instances to audit what provider packages will be removed
  • Use --quiet mode with environment variables pre-configured for CI/CD pipelines
  • Schedule regular re-runs (monthly) to apply updated hardening recommendations
  • Monitor /var/log/du_setup_report_*.txt outputs for drift detection

For Security-Conscious Organizations:

  • Mandate SHA256 verification in your internal runbooks
  • Fork the repository and pin to specific commits rather than main
  • Integrate Lynis audit outputs into your SIEM or security dashboard
  • Use the --skip-cleanup flag if provider agents are required for compliance monitoring

For Multi-Server Environments:

  • Combine du_setup with configuration management (Ansible, Salt) by using it for initial bootstrap only
  • Store backup encryption keys separately from backup destinations
  • Test SSH lockout recovery procedures quarterly using provider consoles

du_setup vs. Alternatives: Why This Script Wins

Feature Manual Setup Cloud-Init Ansible/Puppet du_setup
Initial setup time 2-4 hours 30 min 1-2 hours setup + runtime 10-15 minutes
Security hardening depth Variable (often incomplete) Basic Configurable (requires expertise) CIS/NIST/OWASP aligned
Idempotent execution ❌ No ⚠️ Partial ✅ Yes ✅ Yes
Configuration backups Manual ❌ No ⚠️ Via roles ✅ Automatic, timestamped
2FA/TOTP setup Manual, error-prone ❌ No Complex ✅ Interactive with QR codes
Backup automation Separate tooling ❌ No Requires custom roles ✅ Built-in rsync + cron
VPN integration Manual ❌ No Complex ✅ Tailscale with custom servers
Security auditing Separate tools ❌ No Separate tools ✅ Lynis + debsecan built-in
Learning curve Low (but error-prone) Medium High Low-Medium
Supply chain verification ❌ No ⚠️ Via images ⚠️ Via Galaxy ✅ SHA256 checksums

The verdict: Ansible and Puppet excel at ongoing configuration management but require substantial upfront investment. Cloud-init is vendor-specific and limited. Manual setup is a liability. du_setup occupies the sweet spot: production-grade security without the configuration management overhead, perfect for initial server provisioning where you need results immediately.

FAQ: Your du_setup Questions Answered

Q: Is du_setup safe to run on existing production servers? A: It's designed for fresh installations. While idempotent, the provider cleanup feature could remove packages your application depends on. Always test in staging first.

Q: Can I customize which hardening rules are applied? A: Yes — du_setup runs interactively by default, letting you enable/disable each feature. For automation, examine the script's environment variable support for non-interactive configuration.

Q: What happens if I get locked out of SSH? A: Use your VPS provider's out-of-band console (VNC, IPMI, etc.) and follow the documented recovery procedure to restore backed-up configurations.

Q: Does du_setup work with ARM64 servers? A: The script focuses on x86_64 Debian/Ubuntu compatibility. ARM64 support depends on package availability — Docker and Tailscale both support ARM64, but verify other components for your specific use case.

Q: How do I update du_setup when new versions release? A: Download the new version, verify its checksum, and re-run. The idempotent design ensures only changed configurations are updated, with fresh backups created.

Q: Can I use du_setup with my existing configuration management? A: Absolutely. Many users run du_setup for initial hardening, then hand off to Ansible/Salt for ongoing application deployment. The --quiet mode enables this handoff cleanly.

Q: Is commercial support available? A: du_setup is MIT-licensed open source without formal commercial support. The active GitHub repository and comprehensive documentation provide community support.

Conclusion: Your Servers Deserve Better Than Copy-Paste

The uncomfortable truth is this: most developers are one misconfigured SSH setting away from a security incident. The time you "save" by skipping proper hardening is borrowed against future incident response — with devastating interest.

du_setup transforms server security from a tedious, error-prone chore into a 10-minute automated process with verifiable, auditable results. It doesn't just save time; it eliminates an entire category of human error that has compromised countless systems.

I've analyzed dozens of server setup tools, and du_setup stands out for its pragmatic completeness — every feature solves a real operational pain point, not a theoretical concern. The SHA256 verification, automatic backups, and rollback procedures reveal engineering discipline that inspires confidence.

Stop reinventing the server setup wheel. Stop trusting your frazzled memory at 2 AM. Stop pretending that curl | bash from a random gist is acceptable infrastructure practice.

👉 Deploy your next server with du_setup: https://github.com/buildplan/du_setup

Clone it. Verify it. Run it. Then sleep soundly knowing your infrastructure baseline is hardened by default, not by hope.


Have you automated your server hardening yet? What's your biggest infrastructure security pain point? Drop a comment — I'd love to hear your war stories.

Comments (0)

Comments are moderated before appearing.

No comments yet. Be the first to share your thoughts!

Support us! ☕