Skip to content

Commit a4bcc52

Browse files
Merge pull request #22 from StrangeRanger/dev
2 parents 3c8c1e0 + 714e9b2 commit a4bcc52

File tree

9 files changed

+396
-214
lines changed

9 files changed

+396
-214
lines changed

README.md

Lines changed: 120 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,118 @@
11
# Linux Security Scripts
22

3-
[![Project Tracker](https://img.shields.io/badge/repo%20status-Project%20Tracker-lightgrey)](https://wiki.hthompson.dev/en/project-tracker)
4-
[![Style Guide](https://img.shields.io/badge/code%20style-Style%20Guide-blueviolet)](https://github.com/StrangeRanger/bash-style-guide)
3+
[![Project Tracker](https://img.shields.io/badge/repo%20status-Project%20Tracker-lightgrey)](https://hthompson.dev/project-tracker#project-293920085)
4+
[![Style Guide](https://img.shields.io/badge/code%20style-Style%20Guide-blueviolet)](https://bsg.hthompson.dev/)
55
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/598c2083cd6f432a910a315fd10aaa66)](https://www.codacy.com/gh/StrangeRanger/linux-security-scripts/dashboard?utm_source=github.com&utm_medium=referral&utm_content=StrangeRanger/linux-security-scripts&utm_campaign=Badge_Grade)
66

7-
This repository is a collection of scripts designed to secure/harden Linux based Distributions.
7+
This repository is a collection of scripts designed to secure/harden Linux-based distributions.
8+
9+
<details>
10+
<summary><strong>Table of Contents</strong></summary>
11+
12+
- [Linux Security Scripts](#linux-security-scripts)
13+
- [Tools and Scripts](#tools-and-scripts)
14+
- [Getting Started](#getting-started)
15+
- [Prerequisites](#prerequisites)
16+
- [Download and Setup](#download-and-setup)
17+
- [Usage](#usage)
18+
- [Quick Start](#quick-start)
19+
- [Individual Script Usage](#individual-script-usage)
20+
- [Post-Installation](#post-installation)
21+
- [Tested On](#tested-on)
22+
- [Other Resources](#other-resources)
23+
- [Security Auditing Tools](#security-auditing-tools)
24+
- [Additional Hardening Resources](#additional-hardening-resources)
25+
- [System Monitoring](#system-monitoring)
26+
- [Support and Issues](#support-and-issues)
27+
- [License](#license)
28+
29+
</details>
30+
31+
## Tools and Scripts
32+
33+
Below is a list of tools included in this repository.
34+
35+
| Tool Name | Description | Category | Requirements | Notes |
36+
|-----------|-------------|----------|--------------|-------|
37+
| **[Lynis Installer](auditing/Lynis%20Installer/lynis-installer.bash)** | Download (clone) Lynis, a security auditing tool for Unix-like systems. | Auditing | Git, Internet connection | No root required |
38+
| **[Root Locker](hardening/Root%20Locker/root-locker.bash)** | Locks the root account to prevent direct logins. | Hardening | Root privileges | Preserves sudo access |
39+
| **[SSHD Hardening](hardening/SSHD%20Hardening/harden-sshd.bash)** | Harden OpenSSH server (sshd) per Lynis recommendations. | Hardening | Root privileges | Creates backups |
40+
| **[UFW Cloudflare](hardening/UFW%20Cloudflare/ufw-cloudflare.bash)** | Configure UFW to only allow HTTP/HTTPS from Cloudflare IP ranges. | Hardening | Root privileges, UFW, Internet connection | Creates backups |
841

9-
<!-- TODO: Add a list of all avaliable scripts and what they do. -->
42+
> [!NOTE]
43+
> All scripts include version information in their headers. Check individual CHANGELOG.md files in each tool's directory for version history and updates.
1044
1145
## Getting Started
1246

13-
### Downloading
47+
### Prerequisites
48+
49+
The following requirements extend to every tool in this repository:
50+
51+
- **Bash**: Version 4.0 or higher
52+
- **Operating System**: Linux-based distribution
53+
54+
> [!NOTE]
55+
> Individual scripts may have additional requirements listed in the table above.
56+
57+
### Download and Setup
1458

1559
All you need to do is download this repository to your local machine:
1660

17-
`git clone https://github.com/StrangeRanger/linux-security-scripts`
61+
```bash
62+
git clone https://github.com/StrangeRanger/linux-security-scripts
63+
cd linux-security-scripts
64+
```
1865

1966
## Usage
2067

21-
> [!NOTE]
22-
> Some of the scripts in this repository require root privileges to run. You can run the scripts with the `sudo` command to give them the necessary permissions.
68+
### Quick Start
69+
70+
For users who want to get started immediately:
71+
72+
1. **Audit your system first**: Run the Lynis installer to download the auditing tool.
73+
```bash
74+
./auditing/Lynis\ Installer/lynis-installer.bash
75+
```
76+
77+
2. **Run a security audit**: Use Lynis to identify security issues.
78+
```bash
79+
cd ~/lynis && sudo ./lynis audit system
80+
```
81+
82+
3. **Apply hardening**: Based on the audit results, run the appropriate hardening scripts with root privileges.
83+
84+
> [!CAUTION]
85+
> **Production Environment Warning**: Always test scripts in a non-production environment first. Some scripts modify critical system configurations and may affect system accessibility.
86+
87+
### Individual Script Usage
88+
89+
You can run any script individually using one of the following methods:
2390

24-
You can run the scripts in this repository by using the following command:
91+
```bash
92+
./[script-name]
93+
```
2594

26-
`./[script name]` OR `bash [script name]`
95+
**or**
96+
97+
```bash
98+
bash [script-name]
99+
```
100+
101+
## Post-Installation
102+
103+
After running the hardening scripts:
104+
105+
1. **Verify SSH access**: Before logging out, test SSH connectivity in a new terminal session.
106+
2. **Review firewall rules**: Check UFW status with `sudo ufw status verbose` if you used the UFW Cloudflare script.
107+
3. **Run Lynis again**: Re-audit your system to see security improvements.
108+
4. **Backup configurations**: Keep copies of any modified configuration files.
109+
110+
> [!WARNING]
111+
> The SSHD hardening script modifies SSH configurations. Ensure you have alternative access to your system before applying changes in production environments.
27112
28113
## Tested On
29114

30-
All of the scripts should work on most, if not all Linux Distributions. With that said, below is a list of Linux Distributions that the scripts have been officially tested and are confirmed to work on.
115+
All of the scripts should work on most, if not all, Linux distributions with Bash v4.0+ installed. With that said, below is a list of Linux distributions that the scripts have been officially tested and are confirmed to work on.
31116

32117
| Distributions | Distro Versions |
33118
| ------------- | ---------------------- |
@@ -36,6 +121,28 @@ All of the scripts should work on most, if not all Linux Distributions. With tha
36121

37122
## Other Resources
38123

39-
While this repository has scripts that can help secure Linux, it's not nearly enough to secure the system as much as it needs to be. Below is a list of other resources that you can/should use to help make your system as secure as possible.
124+
Below is a list of additional resources that you can/should use to help make your system as secure as possible.
125+
126+
### Security Auditing Tools
127+
128+
- [SSH Audit](https://github.com/jtesta/ssh-audit) - SSH server & client auditing (banner, key exchange, encryption, mac, compression, compatibility, security, etc)
129+
130+
### Additional Hardening Resources
131+
132+
- [CIS Benchmarks](https://www.cisecurity.org/cis-benchmarks) - Industry-standard security configuration guidelines
133+
- [NIST Cybersecurity Framework](https://www.nist.gov/cyberframework) - Comprehensive cybersecurity guidance
134+
- [OpenSCAP](https://www.open-scap.org/) - Security compliance and vulnerability management
135+
136+
### System Monitoring
137+
138+
- [AIDE](https://aide.github.io/) - Advanced Intrusion Detection Environment
139+
- [Fail2Ban](https://github.com/fail2ban/fail2ban) - Intrusion prevention software
140+
- [rkhunter](http://rkhunter.sourceforge.net/) - Rootkit detection tool
141+
142+
## Support and Issues
143+
144+
Please use [GitHub Issues](https://github.com/StrangeRanger/linux-security-scripts/issues) for bug reports and feature requests.
145+
146+
## License
40147

41-
- [SSH Audit](https://github.com/jtesta/ssh-audit) - SSH server & client auditing (banner, key exchange, encryption, mac, compression, compatibility, security, etc).
148+
Licensing may vary by tool; see individual file headers.

auditing/Lynis Installer/CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## v1.0.9 - 2025-08-10
8+
9+
### Removed
10+
11+
- Remove pointless `-e` flag in `echo`.
12+
713
## v1.0.8 - 2024-12-20
814

915
### Changed
@@ -17,7 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1723
- No longer requires root permission to run the script.
1824
- Won't download lynis if is already present on the system.
1925
- Improved syntax of the script.
20-
- Rename script to `lynis-installer.bash`.
26+
- Rename script to `lynis-installer.bash`.
2127

2228
## v1.0.6 - 2024-04-13
2329

auditing/Lynis Installer/lynis-installer.bash

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
# it. Unless an error is encountered, Lynis will always be downloaded to the current
66
# user's root directory (`/home/USERNAME/`).
77
#
8-
# Version: v1.0.8
8+
# Version: v1.0.9
99
# License: MIT License
10-
# Copyright (c) 2020-2024 Hunter T. (StrangeRanger)
10+
# Copyright (c) 2020-2025 Hunter T. (StrangeRanger)
1111
#
1212
########################################################################################
1313

@@ -48,5 +48,5 @@ git clone https://github.com/CISOfy/lynis || {
4848
}
4949

5050
echo -e "\n${C_SUCCESS}Lynis has been downloaded to your system"
51-
echo -e "${C_NOTE}To perform a system scan with lynis, execute the following command" \
51+
echo "${C_NOTE}To perform a system scan with lynis, execute the following command" \
5252
"in the lynis root directory: sudo ./lynis audit system"

hardening/Root Locker/CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## v1.0.10 - 2025-08-10
8+
9+
### Changed
10+
11+
- Replace `[[ ]]` with `(( ))`.
12+
- Remove redundant comments.
13+
14+
## v1.0.9 - 2025-08-09
15+
16+
### Changed
17+
18+
- Removed "Exiting..." message from output.
19+
720
## v1.0.8 - 2024-12-20
821

922
### Changed

hardening/Root Locker/root-locker.bash

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
# Locking the root account doesn't prevent users from using something like `sudo su`
77
# to gain root access.
88
#
9-
# Version: v1.0.8
9+
# Version: v1.0.10
1010
# License: MIT License
11-
# Copyright (c) 2020-2024 Hunter T. (StrangeRanger)
11+
# Copyright (c) 2020-2025 Hunter T. (StrangeRanger)
1212
#
1313
########################################################################################
1414

@@ -24,10 +24,8 @@ C_INFO="${C_BLUE}==>${C_NC} "
2424
C_NOTE="${C_CYAN}==>${C_NC} "
2525

2626

27-
## Check if this script was executed with root privilege.
28-
if [[ $EUID != 0 ]]; then
27+
if (( EUID != 0 )); then
2928
echo "${C_ERROR}Please run this script as or with root privilege" >&2
30-
echo -e "\n${C_INFO}Exiting..."
3129
exit 1
3230
fi
3331

@@ -37,7 +35,6 @@ read -rp "${C_NOTE}We will now disable the root account. Press [Enter] to contin
3735
echo "${C_INFO}Disabling root account..."
3836
usermod -L root || {
3937
echo -e "${C_ERROR}Failed to lock the root account" >&2
40-
echo -e "\n${C_INFO}Exiting..."
4138
exit 1
4239
}
4340

hardening/SSHD Hardening/CHANGELOG.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,22 @@
22

33
All notable changes to this project will be documented in this file.
44

5-
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6+
7+
## v2.1.0 - 2025-08-09
8+
9+
### Added
10+
11+
- **Session backup system**: Automatic restoration during script interruptions with temporary backup preservation for manual recovery
12+
- **Cross-platform SSH service restart**: Automatically detects and restarts either `sshd` or `ssh` service based on distribution
13+
- **Enhanced signal handling**: Proper restoration and cleanup on script interruption (SIGHUP, SIGINT, SIGTERM)
14+
15+
### Changed
16+
17+
- **Backup strategy**: Dual backup system with permanent `.bak` file for user reference and session backup for auto-restoration
18+
- **Exit handling**: Strategic use of `clean_exit` function only when cleanup or restoration is needed
19+
- **User messaging**: Enhanced feedback throughout backup, restoration, and cleanup processes
20+
- **Output colors**: "Already set" messages now use note (cyan) instead of success (green) for better semantic clarity
621

722
## v2.0.2 - 2024-12-20
823

0 commit comments

Comments
 (0)