↓ Skip to main content

Common One-Click Scripts for Linux Operations and Maintenance

·774 words·4 mins

This article consolidates commonly used one-click Bash scripts for Linux operations and maintenance (O&M). These scripts simplify repetitive administrative tasks such as service installation, system updates, backups, monitoring, and environment setup.


🌐 One-click Apache Server Installation
#

#!/bin/bash
sudo apt-get update
sudo apt-get install -y apache2
sudo systemctl start apache2
sudo systemctl enable apache2
echo "Apache server installed and started"

Purpose: Installs and enables the Apache HTTP server with systemd autostart.


🗄️ One-click MySQL Server Installation
#

#!/bin/bash
sudo apt-get update
sudo apt-get install -y mysql-server
sudo mysql_secure_installation
sudo systemctl start mysql
sudo systemctl enable mysql
echo "MySQL database installed and started"

Purpose: Installs MySQL and performs initial security configuration.


💾 One-click MySQL Database Backup
#

#!/bin/bash
USER="your_mysql_user"
PASSWORD="your_mysql_password"
DB_NAME="your_database_name"
BACKUP_DIR="/path/to/backup"
DATE=$(date +"%Y-%m-%d")

mkdir -p "$BACKUP_DIR"
mysqldump -u "$USER" -p"$PASSWORD" "$DB_NAME" > "$BACKUP_DIR/$DB_NAME-$DATE.sql"
echo "Database backed up successfully"

Purpose: Creates a timestamped backup of a MySQL database.


🚀 One-click Nginx Installation
#

#!/bin/bash
sudo apt-get update
sudo apt-get install -y nginx
sudo systemctl start nginx
sudo systemctl enable nginx
echo "Nginx server installed and started"

Purpose: Installs and enables the Nginx web server.


🔥 One-click Firewall Configuration (UFW)
#

#!/bin/bash
sudo ufw allow 'Nginx Full'
sudo ufw allow 'OpenSSH'
sudo ufw --force enable
sudo ufw status
echo "Firewall configured and enabled"

Purpose: Configures the firewall to allow web and SSH traffic.


🔄 One-click System Update
#

#!/bin/bash
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get dist-upgrade -y
echo "System updated successfully"

Purpose: Updates system packages to the latest versions.


🐳 One-click Docker Installation
#

#!/bin/bash
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker.gpg
echo "deb [signed-by=/usr/share/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list

sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
sudo systemctl enable --now docker
sudo usermod -aG docker "$USER"
echo "Docker installed successfully"

Purpose: Installs Docker and enables non-root usage.


🧹 One-click System Log Cleanup
#

#!/bin/bash
sudo journalctl --vacuum-time=7d
sudo find /var/log -type f -name "*.log" -exec truncate -s 0 {} \;
echo "System logs cleaned"

Purpose: Frees disk space by clearing old logs.


🐘 One-click PHP Installation
#

#!/bin/bash
sudo apt-get update
sudo apt-get install -y php libapache2-mod-php php-mysql
sudo systemctl restart apache2
echo "PHP installed and configured"

Purpose: Installs PHP and integrates it with Apache.


📊 One-click CPU and Memory Monitoring
#

#!/bin/bash
watch -n 1 'free -m && echo && top -bn1 | grep "Cpu(s)"'

Purpose: Displays real-time CPU and memory usage.


🔍 One-click Large File Search #

#!/bin/bash
sudo find / -type f -size +100M -exec ls -lh {} \; 2>/dev/null \
| awk '{ print $NF ": " $5 }'

Purpose: Identifies files larger than 100MB.


🌱 One-click Git Installation
#

#!/bin/bash
sudo apt-get update
sudo apt-get install -y git
echo "Git installed"

Purpose: Installs Git version control.


🟢 One-click Node.js Installation
#

#!/bin/bash
VERSION="18"
curl -fsSL https://deb.nodesource.com/setup_$VERSION.x | sudo -E bash -
sudo apt-get install -y nodejs
echo "Node.js installed"

Purpose: Installs a modern LTS version of Node.js.


⚡ One-click Redis Installation
#

#!/bin/bash
sudo apt-get update
sudo apt-get install -y redis-server
sudo systemctl enable --now redis
echo "Redis installed and started"

Purpose: Installs and starts Redis.


🍃 One-click MongoDB Installation
#

#!/bin/bash
curl -fsSL https://pgp.mongodb.com/server-6.0.asc | sudo gpg --dearmor -o /usr/share/keyrings/mongodb.gpg
echo "deb [signed-by=/usr/share/keyrings/mongodb.gpg] \
https://repo.mongodb.org/apt/ubuntu $(lsb_release -sc)/mongodb-org/6.0 multiverse" \
| sudo tee /etc/apt/sources.list.d/mongodb-org.list

sudo apt-get update
sudo apt-get install -y mongodb-org
sudo systemctl enable --now mongod
echo "MongoDB installed and started"

Purpose: Installs MongoDB from the official repository.


🔐 One-click SSH Passwordless Login
#

#!/bin/bash
read -p "Enter SSH key path: " KEY_PATH
read -p "Enter user@host: " TARGET
ssh-copy-id -i "$KEY_PATH" "$TARGET"
echo "Passwordless SSH configured"

Purpose: Enables SSH key-based authentication.


🐍 One-click Python Virtual Environment Tools
#

#!/bin/bash
sudo apt-get update
sudo apt-get install -y python3 python3-venv python3-pip
echo "Python environment tools installed"

Purpose: Prepares Python virtual environment support.


📦 One-click Directory Compression
#

#!/bin/bash
read -p "Directory to compress: " DIR
read -p "Archive name: " NAME
tar -czvf "$NAME.tar.gz" -C "$(dirname "$DIR")" "$(basename "$DIR")"
echo "Directory compressed"

Purpose: Compresses a directory into a .tar.gz archive.


☕ One-click Java Installation
#

#!/bin/bash
sudo apt-get update
sudo apt-get install -y openjdk-17-jdk
echo "Java installed"

Purpose: Installs OpenJDK LTS.


💽 One-click Disk Space Check
#

#!/bin/bash
df -h | grep -Ev 'tmpfs|udev'

Purpose: Displays disk usage excluding temporary filesystems.


✅ Conclusion
#

These one-click scripts address the most common Linux O&M scenarios, including web services, databases, containers, monitoring, and development environments. They are ideal for learning, quick setups, and internal automation. Always review scripts carefully and test them in a controlled environment before production use.

Related