Skip to content

A linux hardening script to install vpn and configure firewall and scan for backdoors and malware

Notifications You must be signed in to change notification settings

passioncoder5/linuxh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

7 Commits
ย 
ย 
ย 
ย 

Repository files navigation

LinuxH - Linux Hardening & Inspection Tool

Bash Platform GitHub

A comprehensive, safe-by-default Linux security hardening and inspection tool designed for system administrators and security professionals.

Note: This script will only be able to install openvpn and configure default firewall and scan for backdoors and malware; rest like connecting to vpn,setting port firewall rules and removing scanned malware need to be manually done as it is not a safe operation for the script to perform

๐Ÿš€ Quick Installation

# Clone the repository
git clone https://github.com/passioncoder5/linuxh.git
cd linuxh

# Make executable
chmod +x linuxh

# Run directly
./linuxh --help

# Or install system-wide (optional)
sudo cp linuxh /usr/local/bin/linuxh

๐Ÿ›ก๏ธ Features

  • Safe by Default: Dry-run mode prevents accidental system changes
  • Comprehensive Security: Multiple hardening modules in one tool
  • Interactive Prompts: Confirms dangerous operations before execution
  • Backup System: Automatically backs up files before modification
  • Cross-Distribution: Supports multiple package managers (APT, YUM, DNF, Pacman, Zypper)
  • Comprehensive Logging: Detailed logs of all actions performed

๐Ÿ“‹ Security Modules

Module Description Safety Level
analyze Network connection analysis ๐Ÿ”’ Read-only
manage-processes Suspicious process management โš ๏ธ Destructive
ufw Firewall configuration โš ๏ธ Destructive
openvpn VPN setup guidance ๐Ÿ”’ Read-only
ssh SSH server hardening โš ๏ธ Destructive
sysctl Kernel security settings โš ๏ธ Destructive
services Legacy service disablement โš ๏ธ Destructive
install-tools Security tools installation โš ๏ธ Destructive
scans Security scans (rkhunter/chkrootkit) ๐Ÿ”’ Read-only
auto-updates Automatic update configuration โš ๏ธ Destructive
all Run complete security suite โš ๏ธ Destructive

๐ŸŽฏ Quick Start Examples

Safety First - Always Test with Dry-Run

# See what would be done without making changes (SAFE)
./linuxh --dry-run all

# Preview specific modules
./linuxh --dry-run ssh
./linuxh --dry-run ufw

Production Usage (Requires Root)

# Apply all security hardening with prompts
sudo ./linuxh --apply all

# Apply specific modules
sudo ./linuxh --apply ssh
sudo ./linuxh --apply ufw
sudo ./linuxh --apply install-tools

# Auto-confirm all prompts (USE WITH CAUTION)
sudo ./linuxh --apply --yes all

โš™๏ธ Command Line Reference

Global Options

--help, -h           Show help message
--dry-run            Show actions without executing (DEFAULT)
--apply              Actually perform changes (requires root)
--yes                Auto-confirm all prompts (dangerous)
--backup-dir DIR     Custom backup directory
--log-file FILE      Custom log file location

Available Commands

# Analysis & Monitoring
./linuxh analyze                    # Network connection analysis
./linuxh manage-processes          # Suspicious process inspection

# System Hardening
sudo ./linuxh --apply ufw          # Configure UFW firewall
sudo ./linuxh --apply ssh          # Harden SSH configuration
sudo ./linuxh --apply sysctl       # Apply kernel hardening
sudo ./linuxh --apply services     # Disable legacy services

# Security Tools
sudo ./linuxh --apply install-tools # Install security tools
sudo ./linuxh --apply scans         # Run security scans
sudo ./linuxh --apply auto-updates  # Configure automatic updates

# Complete Suite
sudo ./linuxh --apply all          # Run all security modules

๐Ÿ”ง What Each Module Does

๐Ÿ” Analyze Module

  • Scans network connections for suspicious ports
  • Identifies processes on known malicious ports
  • Ports monitored: 4444, 1337, 31337, 6667, 9999, 12345, 54321
  • Safety: Read-only, non-destructive

โš ๏ธ Manage Processes

  • Finds processes listening on suspicious ports
  • Optionally kills suspicious processes
  • Can remove malicious executables
  • Creates backups before any removal

๐Ÿ”ฅ UFW Firewall

  • Installs and configures UFW firewall
  • Sets default deny incoming, allow outgoing
  • Configures essential ports (SSH, HTTP, HTTPS)
  • Can detect and allow running services

๐Ÿ”’ SSH Hardening

  • Disables root login
  • Disables password authentication (keys only)
  • Sets MaxAuthTries to 3
  • Disables X11 forwarding
  • Tests configuration before applying

โš™๏ธ Kernel Hardening

  • Applies security-focused sysctl settings
  • Disables IP forwarding and redirects
  • Enables TCP syncookies
  • Restricts kernel pointer access

๐Ÿšซ Service Management

  • Disables legacy insecure services:
    • telnet.socket
    • rsh.socket
    • rexec.socket
    • rlogin.socket

๐Ÿ› ๏ธ Security Tools

Installs and configures:

  • fail2ban - Intrusion prevention
  • clamav - Antivirus scanning
  • rkhunter - Rootkit detection
  • chkrootkit - Rootkit scanning

๐Ÿ” Security Scans

  • Runs rkhunter rootkit scan
  • Runs chkrootkit scan
  • Updates virus definitions
  • Non-destructive scanning

๐Ÿ”„ Auto Updates

  • Configures automatic security updates
  • Supports APT (unattended-upgrades)
  • Supports YUM/DNF (dnf-automatic/yum-cron)

๐ŸŽจ Features in Detail

๐Ÿ›ก๏ธ Safety First Design

# Default behavior: SAFE dry-run
./linuxh ssh                    # Shows what would be done
./linuxh --dry-run ssh         # Explicit dry-run (same as above)

# Explicit apply required for changes
sudo ./linuxh --apply ssh      # Actually makes changes

๐Ÿ“ Comprehensive Logging

  • All actions logged to /var/log/linuxh_security.log
  • Timestamped entries
  • Both success and error logging
  • Dry-run commands logged for audit

๐Ÿ’พ Smart Backups

  • Automatic backup before file modifications
  • Customizable backup directory
  • Timestamped backup files
  • Backup restoration on errors

๐ŸŽฏ Interactive Prompts

Disable root login? [y/N]: y
Disable password authentication? [y/N]: y
Apply these SSH changes? [y/N]: y

๐ŸŒ Cross-Distribution Support

  • Debian/Ubuntu: APT package manager
  • RedHat/CentOS: YUM package manager
  • Fedora: DNF package manager
  • Arch Linux: Pacman package manager
  • OpenSUSE: Zypper package manager

โš ๏ธ Important Warnings

๐Ÿšจ Critical Safety Notes

  1. ALWAYS test with --dry-run first
  2. SSH hardening may lock you out if key-based auth isn't setup
  3. Some changes require reboot to take full effect
  4. Backup important data before applying changes
  5. Test on non-production systems first

๐Ÿ” SSH Hardening Warning

The SSH module will:

  • โŒ Disable root login
  • โŒ Disable password authentication (keys only)
  • โŒ Reduce MaxAuthTries to 3
  • โŒ Disable X11 forwarding

Ensure you have SSH key authentication working before applying!

๐Ÿ› Troubleshooting

Common Issues & Solutions

Permission Denied Errors

# Use sudo for apply mode
sudo ./linuxh --apply ssh

# Ensure log directory exists
sudo mkdir -p /var/log

SSH Service Not Found

# Check available services
systemctl list-unit-files | grep -i ssh

# Install SSH server if needed
sudo apt update && sudo apt install openssh-server

Package Manager Detection Issues

# Manual package manager override
sudo ./linuxh --apply install-tools
# Script auto-detects: APT, YUM, DNF, Pacman, Zypper

Log Files and Debugging

# Check execution logs
sudo tail -f /var/log/linuxh_security.log

# Check backup directory
sudo ls -la /root/security_backup_*/

# Dry-run to debug
./linuxh --dry-run all

๐Ÿ“Š Example Output

Dry-run Mode

[DRY-RUN] ufw --force reset
[DRY-RUN] ufw default deny incoming
[DRY-RUN] ufw allow 22
โœ… No suspicious connections found.
โš  Found 2 suspicious processes

Success Messages

โœ… SSH config applied and sshd restarted
โœ… UFW enabled with configured rules  
โœ… Kernel settings applied
โœ… Security tools installed successfully

๐Ÿ”ฎ Advanced Usage

Custom Configuration

Edit the script to modify default values:

# Customize suspicious ports
SUSPICIOUS_PORTS=(4444 1337 31337 6667 9999 12345 54321 8080 8443)

# Customize essential ports  
ESSENTIAL_PORTS=(22 80 443 53 993 995)

# Change default locations
BACKUP_DIR_DEFAULT="/opt/security_backups"
LOG_FILE_DEFAULT="/var/log/custom_security.log"

Integration with Other Tools

# Run as part of deployment script
sudo ./linuxh --apply --yes ufw
sudo ./linuxh --apply --yes sysctl
sudo ./linuxh --apply --yes auto-updates

# Schedule regular security scans
0 2 * * * /path/to/linuxh --apply scans

๐Ÿค Contributing

We welcome contributions! Here's how:

  1. Fork the repository

    git clone https://github.com/passioncoder5/linuxh.git
    cd linuxh
  2. Create a feature branch

    git checkout -b feature/new-security-module
  3. Make your changes and test

    ./linuxh --dry-run all
    sudo ./linuxh --apply your-module
  4. Submit a pull request

Areas for Contribution

  • New security modules
  • Additional package manager support
  • Enhanced detection capabilities
  • Documentation improvements
  • Bug fixes and optimizations

๐Ÿ†˜ Support

  • GitHub Issues: Report bugs or request features
  • Security Concerns: Please report security vulnerabilities privately
  • Documentation: Check this README and script comments

๐ŸŒŸ Star History

If you find this tool useful, please consider giving it a star on GitHub!


Remember: Security is a process, not a product. Always test changes in a safe environment before deploying to production systems.

Stay safe, stay secure! ๐Ÿ”

About

A linux hardening script to install vpn and configure firewall and scan for backdoors and malware

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages