Modern, secure, and cross-platform system administration scripts for Linux servers.
This repository contains a comprehensive collection of bash and Python scripts designed to automate and simplify common system administration tasks on Linux servers. The scripts have been modernized with security best practices, multi-OS support, and extensive error handling.
- ✅ Multi-OS Support: RHEL 8/9, Rocky Linux, AlmaLinux, CentOS Stream, Ubuntu 20.04+, Debian 11+
- ✅ Security-First: No hardcoded credentials, input validation, secure password handling
- ✅ Modern Standards: set -euo pipefail, comprehensive error handling, proper logging
- ✅ Shared Library: Reusable functions via lib/common.sh
- ✅ Configuration Files: Template-based configuration in config/directory
- ✅ Dry-Run Mode: Test scripts without making actual changes
- ✅ Comprehensive Logging: Syslog integration and colored terminal output
# Clone the repository
git clone https://github.com/yourusername/sysadmin-shell-scripts.git
cd sysadmin-shell-scripts
# Example: Install Ansible
sudo ./installation_scripts/install_ansible.sh
# Example: Backup /etc directory with 30-day retention
sudo ./miscellaneous/etcbackup.sh
# Example: Check if port 22 is open on a host
python3 python-scripts/portcheck.py example.com 22sysadmin-shell-scripts/
├── lib/                          # Shared function library
│   └── common.sh                 # Common functions for all scripts
├── config/                       # Configuration templates
│   ├── defaults.conf             # Global defaults
│   ├── *.conf.example            # Script-specific configs
│   └── README.md                 # Configuration guide
├── installation_scripts/         # Software installation scripts
│   ├── install_ansible.sh
│   ├── install_flask.sh
│   ├── install_jenkins.sh
│   ├── install_nagios.sh
│   ├── install_nginx.sh
│   ├── install_python3.sh
│   ├── install_salt.sh
│   ├── install_salt_minion.sh
│   └── install_squid.sh
├── miscellaneous/                # Utility scripts
│   ├── checkssh_conn.sh          # Check SSH connections
│   ├── dirbackup.sh              # Directory backup
│   ├── etcbackup.sh              # /etc backup
│   ├── passgen.sh                # Password generator
│   └── webpagedl.sh              # Webpage downloader
├── python-scripts/               # Python utilities
│   ├── checkcpu.py               # CPU information
│   ├── portcheck.py              # Port connectivity checker
│   └── timer.py                  # Execution timer
└── server_management/            # Server management scripts
    ├── CentOS/
    │   ├── change_hostname.sh    # Change server hostname
    │   ├── create_db.sh          # MySQL database creator
    │   ├── permissive_selinux.sh # SELinux configuration
    │   ├── sync_emails.sh        # IMAP email sync
    │   ├── system_stats.sh       # System statistics
    │   └── nginx/
    │       └── newuser.sh        # Create Nginx user
    └── Debian/
        └── install_salt_minion.sh # Salt minion for Debian
| Script | Description | OS Support | 
|---|---|---|
| install_ansible.sh | Install Ansible automation platform | RHEL, Debian | 
| install_flask.sh | Install Flask + Nginx + Gunicorn stack | RHEL | 
| install_jenkins.sh | Install Jenkins CI/CD server | RHEL | 
| install_nagios.sh | Install Nagios monitoring system | RHEL | 
| install_nginx.sh | Install Nginx web server | RHEL | 
| install_python3.sh | Compile Python 3 from source | RHEL | 
| install_salt.sh | Install SaltStack master & minion | RHEL | 
| install_salt_minion.sh | Install SaltStack minion only | RHEL, Debian | 
| install_squid.sh | Install Squid proxy server | RHEL | 
# Install Ansible (as root)
sudo ./installation_scripts/install_ansible.sh
# Install Flask application with domain
sudo ./installation_scripts/install_flask.sh example.com
# Install Jenkins
sudo ./installation_scripts/install_jenkins.sh
# Install Python 3 from source
sudo ./installation_scripts/install_python3.sh# Backup /etc directory
sudo ./miscellaneous/etcbackup.sh
# Backup any directory
sudo ./miscellaneous/dirbackup.sh /var/www# Generate secure passwords
./miscellaneous/passgen.sh 5 20  # 5 passwords, 20 characters each
# Check SSH connections
sudo ./miscellaneous/checkssh_conn.sh# Download webpage
./miscellaneous/webpagedl.sh https://example.com# Install Python dependencies
pip3 install -r python-scripts/requirements.txt# Check CPU cores
python3 python-scripts/checkcpu.py
# Check if port is open
python3 python-scripts/portcheck.py example.com 80
# Time command execution
python3 python-scripts/timer.pysudo ./server_management/CentOS/change_hostname.sh new-hostnamesudo ./server_management/CentOS/create_db.sh <mysql_root_password>sudo ./server_management/CentOS/system_stats.shMany scripts support configuration files. See config/README.md for details.
# Copy example config
cp config/backup.conf.example config/backup.conf
# Edit configuration
vim config/backup.conf
# Use in scripts (auto-loaded)
./miscellaneous/etcbackup.shAll scripts can leverage shared functions from lib/common.sh:
#!/usr/bin/env bash
set -euo pipefail
# Source common library
source "$(dirname "$0")/../lib/common.sh"
# Use library functions
require_root
print_info "Starting installation..."
validate_domain "example.com"
log_success "Installation complete"Available functions:
- Color output: print_info,print_success,print_warning,print_error
- OS detection: detect_os,detect_os_version,get_package_manager
- Validation: validate_domain,validate_ip,validate_port,validate_hostname
- Backups: backup_file,backup_dir
- Logging: log_info,log_error,log_success
- Network: get_public_ip,get_private_ip,check_internet
- And many more...
See lib/common.sh for complete documentation.
| Operating System | Version | Status | 
|---|---|---|
| RHEL | 8, 9 | ✅ Tested | 
| Rocky Linux | 8, 9 | ✅ Tested | 
| AlmaLinux | 8, 9 | ✅ Tested | 
| CentOS Stream | 8, 9 | ✅ Tested | 
| CentOS | 7 | |
| Ubuntu | 20.04, 22.04, 24.04 | 🔄 Partial | 
| Debian | 11, 12 | 🔄 Partial | 
Legend:
- ✅ Fully supported and tested
- 🔄 Partially supported (some scripts)
- ⚠️ Legacy support (no new features)
- No Hardcoded Credentials: Use read -sfor password input
- Input Validation: All user inputs are validated
- Principle of Least Privilege: Root checks where necessary
- Secure Defaults: SELinux enabled, strong passwords required
- Logging: All operations logged to syslog
- Backup Before Modify: Configuration files backed up automatically
- Some scripts require root access
- Network-dependent operations may fail without internet
- SELinux may need policy adjustments for some operations
- Bash 4.0+
- Python 3.9+
- ShellCheck (for linting)
- BATS (for testing)
# Shell script tests
bats tests/*.sh
# Python tests
pytest tests/See CONTRIBUTING.md for guidelines on:
- Code style
- Testing requirements
- Pull request process
- Commit message format
Issue: Script fails with "command not found"
# Solution: Install missing dependencies
sudo dnf install <package>  # RHEL-based
sudo apt install <package>  # Debian-basedIssue: Permission denied
# Solution: Run with sudo if root required
sudo ./script.shIssue: SELinux denials
# Solution: Check audit logs and create policy
sudo ausearch -m avc -ts recent
sudo audit2allow -a -M mypolicy
sudo semodule -i mypolicy.pp- Complete multi-OS support for all scripts
- Add Docker/Podman installation scripts
- Add Kubernetes setup scripts
- Implement automated testing (CI/CD)
- Add S3 backup support
- Add email notification support
- Create interactive menus for complex scripts
See CHANGELOG.md for version history.
This project is licensed under the MIT License - see the LICENSE file for details.
- Original scripts created for CentOS/RHEL administration
- Modernized with community feedback and best practices
- Inspired by system administration needs across diverse environments
- Issues: Report bugs via GitHub Issues
- Discussions: Join community discussions
- Documentation: Check config/README.mdand inline script comments
Note: Always test scripts in a non-production environment first. Use the --dry-run flag where available to preview changes.