Skip to main content

Common One-Click Scripts for Linux Operations and Maintenance

·774 words·4 mins
Linux Script DevOps O&M
Table of Contents

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

10 Advanced Linux Shell Scripting Techniques for Production in 2025
·595 words·3 mins
Linux Shell Scripting Bash DevOps Automation
Linus Torvalds Criticizes x86 Microarchitecture Levels as 'Broken Garbage'
·523 words·3 mins
Linux X86 CPU Kernel
Embedded BSP Development: Roles, Challenges, and Best Practices
·796 words·4 mins
Embedded Systems BSP Linux