# hosteons/linux-hardening-script architecture

> Architecture diagram of the GitHub repository hosteons/linux-hardening-script, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hosteons/linux-hardening-script
- Repository: https://github.com/hosteons/linux-hardening-script

## Overview

1. **Repository shape**
   - This is a very small, single-purpose repository: one shell entrypoint (`harden.sh`), documentation, and a license.
   - The architecture is not a multi-service app; it is a **local host automation script** that directly modifies the machine it runs on.

2. **Primary runtime boundary**
   - The script runs **on the target Linux VPS/server itself** with administrative privileges.
   - There is no separate backend, API, database, or UI layer. The “system under management” is the Linux host.

3. **Supported environments**
   - The script targets four Linux families: **Ubuntu, Debian, CentOS, and AlmaLinux**.
   - That implies distro-aware branching around package management, firewall/SELinux behavior, and SSH service configuration.

4. **Main orchestration role of `harden.sh`**
   - `harden.sh` is the central orchestrator for all hardening tasks.
   - It likely runs as a linear workflow: update the system, apply security changes, install hardening tools, then run an audit.

5. **Operational input boundary**
   - The operator is part of the architecture: the script prompts for choices such as **SSH port changes**, **root login disabling**, and **new sudo user setup**.
   - The script is therefore partially interactive, with safety-sensitive decisions made at runtime rather than predeclared config.

6. **System update and package-management flow**
   - One subsystem is the **update/install layer**, which brings the host to a current state before hardening.
   - This layer interacts with the OS package manager and is the dependency foundation for all later steps.

7. **SSH hardening subsystem**
   - SSH is a central security boundary in this repo.
   - The script can **change the SSH port** and optionally **disable root login**, which directly affects remote access and remote administration paths.

8. **Access-control / user-management subsystem**
   - Another branch of the workflow is **sudo user provisioning**.
   - The script can create or prepare a non-root administrative user, shifting privileged access away from direct root use.

9. **Firewall and network exposure subsystem**
   - The script configures the host firewall, which is the main network-layer enforcement boundary.
   - This subsystem works together with the SSH changes to reduce exposed services and constrain inbound access.

10. **Brute-force protection and audit tooling**
    - The repo installs and uses **Fail2Ban** for intrusion prevention and **Lynis** for security auditing.
    - Fail2Ban is a reactive protection layer; Lynis is a post-change validation/audit layer.

11. **SELinux handling**
    - For CentOS/AlmaLinux, SELinux is explicitly part of the hardening model.
    - This introduces an OS security-policy layer distinct from firewalling and SSH config, so architecture diagrams should show it as a separate host-control boundary.

12. **Execution outcome**
    - The script’s output is a **hardened server state** rather than an ongoing service.
    - The main data flow is: operator input → system changes on the host → security tools installed/configured → audit feedback from Lynis.

13. **External dependencies**
    - The only meaningful external dependencies are OS-level services and tools: SSH daemon, firewall tooling, package managers, Fail2Ban, Lynis, and SELinux.
    - Hosteons appears only as attribution in the README and does not change the runtime architecture.

14. **What to diagram**
    - For an architecture diagram, treat this repo as a **single automation component** connected to one target machine.
    - Show the operator feeding decisions into `harden.sh`, and the script driving changes to system packages, SSH, firewall, SELinux, and security tooling on the local server.

Main entry points: [`harden.sh`](https://github.com/hosteons/linux-hardening-script/blob/main/harden.sh) (harden.sh)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_repo["Repository"]
  node_harden_script["harden.sh<br/>orchestrator<br/>[harden.sh]"]
end

subgraph group_host["Target Host"]
  node_os_packages[("Package Layer<br/>system update")]
  node_distro_branch{{"Distro Rules<br/>os branching"}}
  node_ssh_daemon[("SSH Daemon<br/>remote access")]
  node_ssh_config["SSH Policy<br/>config"]
  node_sudo_user(("Sudo User<br/>access control"))
  node_firewall[("Firewall<br/>network control")]
  node_selinux[("SELinux<br/>policy enforcement")]
  node_hardened_state(("Hardened Host<br/>outcome"))
  node_package_mgr[("Pkg Manager<br/>system tool")]
end

subgraph group_tools["Security Tools"]
  node_fail2ban[("Fail2Ban<br/>intrusion prevention")]
  node_lynis[("Lynis<br/>security audit")]
end

node_operator(("Operator<br/>human"))
node_ssh_port(("SSH Port<br/>runtime choice"))
node_root_login(("Root Login<br/>runtime choice"))

node_operator -->|"runs"| node_harden_script
node_operator -->|"chooses"| node_ssh_port
node_operator -->|"chooses"| node_root_login
node_harden_script -->|"detects"| node_distro_branch
node_harden_script -->|"updates"| node_os_packages
node_os_packages -->|"uses"| node_package_mgr
node_harden_script -->|"configures"| node_ssh_config
node_ssh_config -->|"controls"| node_ssh_daemon
node_ssh_port -->|"feeds"| node_ssh_config
node_root_login -->|"feeds"| node_ssh_config
node_harden_script -->|"provisions"| node_sudo_user
node_harden_script -->|"enforces"| node_firewall
node_ssh_config -->|"aligns"| node_firewall
node_harden_script -->|"handles"| node_selinux
node_distro_branch -->|"gates"| node_selinux
node_harden_script -->|"installs"| node_fail2ban
node_harden_script -->|"audits"| node_lynis
node_lynis -->|"validates"| node_hardened_state
node_fail2ban -->|"protects"| node_hardened_state
node_firewall -->|"constrains"| node_hardened_state
node_ssh_daemon -->|"serves"| node_hardened_state

click node_harden_script "https://github.com/hosteons/linux-hardening-script/blob/main/harden.sh"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_harden_script toneBlue
class node_os_packages,node_distro_branch,node_ssh_daemon,node_ssh_config,node_sudo_user,node_firewall,node_selinux,node_hardened_state,node_package_mgr toneAmber
class node_fail2ban,node_lynis toneMint
class node_operator,node_ssh_port,node_root_login toneNeutral
```

## Components

### Repository

The automation entrypoint and documentation in this project.

- [harden.sh](https://github.com/hosteons/linux-hardening-script/blob/main/harden.sh): orchestrator · Main shell workflow that applies host hardening steps. · `harden.sh`

### Target Host

The Linux server being modified in place by the script.

- **Package Layer**: system update · OS package management and baseline updates before hardening.
- **Distro Rules**: os branching · Ubuntu, Debian, CentOS, and AlmaLinux-specific handling.
- **SSH Daemon**: remote access · Remote administration service whose config is hardened.
- **SSH Policy**: config · Port changes and root-login restrictions for SSH access.
- **Sudo User**: access control · Non-root administrative account prepared for safer access.
- **Firewall**: network control · Inbound network filtering aligned with the SSH policy.
- **SELinux**: policy enforcement · Mandatory access control handling on CentOS and AlmaLinux.
- **Hardened Host**: outcome · Final secured server state after changes and audit.
- **Pkg Manager**: system tool · Underlying distro package manager used to install and update components.

### Security Tools

External host-level tools and services used during hardening.

- **Fail2Ban**: intrusion prevention · Brute-force protection for exposed services, especially SSH.
- **Lynis**: security audit · Post-change audit and validation of the hardened host.

### Other components

- **Operator**: human · Admin choosing hardening options at runtime.
- **SSH Port**: runtime choice · Interactive choice controlling the remote access endpoint.
- **Root Login**: runtime choice · Interactive choice to keep or disable root SSH access.

## Connections

- Operator → harden.sh: runs · The operator starts the hardening workflow on the target host.
- Operator → SSH Port: chooses · Runtime input for SSH port selection.
- Operator → Root Login: chooses · Runtime input for root SSH login policy.
- harden.sh → Distro Rules: detects · Branches behavior by Linux family.
- harden.sh → Package Layer: updates · Brings the base system current before hardening.
- Package Layer → Pkg Manager: uses · Relies on the host package manager.
- harden.sh → SSH Policy: configures · Applies SSH hardening choices and policy.
- SSH Policy → SSH Daemon: controls · Updates the SSH service behavior.
- SSH Port → SSH Policy: feeds · Selected port is written into SSH policy.
- Root Login → SSH Policy: feeds · Chosen root-login policy is written into SSH policy.
- harden.sh → Sudo User: provisions · Sets up or prepares a non-root admin account.
- harden.sh → Firewall: enforces · Configures inbound filtering and port exposure.
- SSH Policy → Firewall: aligns · Firewall rules must match the SSH access path.
- harden.sh → SELinux: handles · Adjusts SELinux-related behavior on supported distros.
- Distro Rules → SELinux: gates · SELinux handling is specific to CentOS and AlmaLinux.
- harden.sh → Fail2Ban: installs · Adds brute-force protection for exposed services.
- harden.sh → Lynis: audits · Runs a security audit after hardening steps.
- Lynis → Hardened Host: validates · Audit feedback reflects the resulting host posture.
- Fail2Ban → Hardened Host: protects · Reactive protection contributes to the final hardened state.
- Firewall → Hardened Host: constrains · Network exposure is reduced in the final state.
- SSH Daemon → Hardened Host: serves · SSH remains the managed remote-access boundary.
