Home

Awesome

Linux Server Hardener

A robust POSIX-compliant shell script that automates security hardening for Linux systems through SSH hardening, intrusion detection, firewall configuration, and granular access controls. This production-grade solution ensures consistent security baselines while maintaining compatibility across major Linux distributions.

WARNING

This script can potentially make your server inaccessible if not used properly. Make sure you:

IMPORTANT: SSH Key Management

After running the script, you MUST:

  1. Save the SSH Private Key

    • Copy the entire private key content (starts with -----BEGIN OPENSSH PRIVATE KEY-----)
    • Store it securely on your local machine as id_ed25519 or similar
    • Keep it strictly private and NEVER share it with anyone
    • Without this key, you cannot access your server
  2. Save the Key Passphrase

    • Store the generated passphrase securely
    • Required every time you use the private key
    • Keep it secret like a password
    • Cannot be recovered if lost
  3. Public Key (Optional Save)

    • The part ending in .pub (starts with ssh-ed25519)
    • Already configured on the server
    • Can be shared safely with others
    • Used for adding access to other servers

Without the private key and passphrase, you will permanently lose access to your server!

Status

Tested and working on:

What's New in v2.0 🚀

Improved Logging 🎯

Documentation 📚

OS Support 🐧

Test with Docker 🐳

Usage

Requirements

Options

# Basic hardening (SSH, Fail2ban, UFW, create & secure SSH key for logged in user)
# Default behavior - no user creation, no root reset, no show credentials info
# Use it when VPS already disabled root password and created new user during setup (e.g. NetCup)
./init-linux-harden.sh

# Create new sudo user during hardening
# Use it when VPS already disabled root password, but no new user created
./init-linux-harden.sh -u jay

# Create new user and reset root password
./init-linux-harden.sh -u jay -r

# Show all credentials in console output (less secure)
./init-linux-harden.sh -u jay -s

Post Installation

sudo ufw status

sudo fail2ban-client status

Features

The script performs comprehensive security hardening:

SSH Hardening

Fail2ban Protection

UFW Firewall

User Management

Backup and Recovery

Logging

To-do

License

Copyright © 2025, Pratik Kumar Tripathy. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.