From b6cb2d31f7224f75d636bc766a2932e8016b4575 Mon Sep 17 00:00:00 2001
From: "LINUXexpert.org" <51408202+LINUXexpert-org@users.noreply.github.com>
Date: Sat, 17 May 2025 10:06:49 -0700
Subject: [PATCH] Add files via upload
---
README.md | 20 ++++++++++++
backup.sh | 43 ++++++++++++++++++++++++++
disk_cleanup.sh | 55 +++++++++++++++++++++++++++++++++
log_inspect.sh | 51 +++++++++++++++++++++++++++++++
log_rotate.sh | 38 +++++++++++++++++++++++
network_info.sh | 53 ++++++++++++++++++++++++++++++++
process_monitor.sh | 40 ++++++++++++++++++++++++
restore.sh | 45 +++++++++++++++++++++++++++
security_audit.sh | 41 +++++++++++++++++++++++++
service_manager.sh | 71 +++++++++++++++++++++++++++++++++++++++++++
sys_monitor.sh | 36 ++++++++++++++++++++++
update_system.sh | 48 +++++++++++++++++++++++++++++
user_manage.sh | 76 ++++++++++++++++++++++++++++++++++++++++++++++
13 files changed, 617 insertions(+)
create mode 100644 README.md
create mode 100644 backup.sh
create mode 100644 disk_cleanup.sh
create mode 100644 log_inspect.sh
create mode 100644 log_rotate.sh
create mode 100644 network_info.sh
create mode 100644 process_monitor.sh
create mode 100644 restore.sh
create mode 100644 security_audit.sh
create mode 100644 service_manager.sh
create mode 100644 sys_monitor.sh
create mode 100644 update_system.sh
create mode 100644 user_manage.sh
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..4b6732f
--- /dev/null
+++ b/README.md
@@ -0,0 +1,20 @@
+# Linux System Administration Scripts
+Linux SysAdmin Bash Scripts Library
+
+
+Automate routine tasks: This project provides a collection of Bash scripts to automate common Linux system administration duties. Automating daily sysadmin tasks improves efficiency and consistency by reducing manual repetition and the risk of human error. Each script is designed to be distribution-agnostic, using only standard base utilities (e.g. rsync, tar, awk, grep, netstat/ss, systemctl) available on most Linux systems. All scripts are released under the GNU GPL v3.0 license and include usage information in their headers.
+
+## Included Scripts
+
+- `backup.sh` – Backup Utility: Archive directories into compressed tarballs for backups.
+- `restore.sh` – Restore Utility: Restore files from backup archives.
+- `disk_cleanup.sh` – Disk Usage & Cleanup: Report disk usage and identify large files; optionally clean package caches and temporary files to free space.
+- `log_inspect.sh` – Log Inspection: Search within log files or tail the latest system logs for troubleshooting.
+- `log_rotate.sh` – Log Rotation: Compress and rotate old log files to prevent excessive disk usage
+- `network_info.sh` – Network & Firewall Info: Show network interface details, routing table, open listening ports, and basic firewall (iptables) rules.
+- `process_monitor.sh` – Process Management: List top resource-consuming processes and allow termination of processes by name or PID.
+- `security_audit.sh`– Security Audit: Scan for security issues like world-writable files, SUID/SGID executables, and open network ports.
+- `service_manager.sh`– Service Management: Start, stop, restart, or check status of system services, and enable/disable services at boot.
+- `sys_monitor.sh` – System Monitoring: Display system uptime, resource utilization (CPU, memory, disk), and top processes.
+- `update_system.sh` – System Updates: Apply available package updates and patches (works with apt, yum/dnf, zypper, pacman).
+- `user_manage.sh` – User and Group Management: Create or remove user accounts and groups, modify user group memberships, and lock/unlock accounts.
diff --git a/backup.sh b/backup.sh
new file mode 100644
index 0000000..80b9b52
--- /dev/null
+++ b/backup.sh
@@ -0,0 +1,43 @@
+#!/bin/bash
+# backup.sh - Backup directory to compressed tar archive
+#
+# Copyright (C) 2025 LINUXexpert.org
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation, version 3 of the License.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see .
+#
+# Usage: backup.sh
+# Description: Creates a tar.gz archive of the source directory in the destination.
+
+SRC="$1"
+DEST="$2"
+if [ -z "$SRC" ] || [ -z "$DEST" ]; then
+ echo "Usage: $0 "
+ exit 1
+fi
+if [ ! -d "$SRC" ]; then
+ echo "Source directory '$SRC' not found!"; exit 1
+fi
+if [ ! -d "$DEST" ]; then
+ # create destination dir if it doesn't exist
+ mkdir -p "$DEST" || { echo "Failed to create destination '$DEST'"; exit 1; }
+fi
+
+base_name="$(basename "$SRC")"
+date_str="$(date +%Y%m%d)"
+archive_name="${base_name}-backup-${date_str}.tar.gz"
+tar -czf "$DEST/$archive_name" -C "$(dirname "$SRC")" "$base_name"
+if [ $? -eq 0 ]; then
+ echo "Backup successful: $DEST/$archive_name"
+else
+ echo "Backup failed for $SRC"
+fi
diff --git a/disk_cleanup.sh b/disk_cleanup.sh
new file mode 100644
index 0000000..a8d29bc
--- /dev/null
+++ b/disk_cleanup.sh
@@ -0,0 +1,55 @@
+#!/bin/bash
+# disk_cleanup.sh - Show disk usage and optionally clean temporary files
+#
+# Copyright (C) 2025 LINUXexpert.org
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation, version 3 of the License.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see .
+#
+# Usage: disk_cleanup.sh [--clean]
+# Description: Without --clean, displays disk usage and largest files. With --clean, performs cleanup of caches and /tmp.
+
+if [ "$1" != "--clean" ]; then
+ echo "==== Disk Usage Overview ===="
+ df -h -x tmpfs -x devtmpfs
+
+ echo -e "\n==== Top 10 Largest Files ===="
+ # List top 10 largest files (size in MB)
+ find / -type f -printf '%s %p\n' 2>/dev/null | sort -nr | head -n 10 | awk '{size=$1/1024/1024; printf("%.1f MB - ", size); $1=""; print $0;}'
+
+ echo -e "\n(To actually free space, run: $0 --clean)"
+ exit 0
+fi
+
+# If --clean is specified:
+echo "Cleaning package caches and temporary files..."
+# Package manager cache cleanup
+if [ $EUID -ne 0 ]; then
+ echo "Run as root to perform cleanup."; exit 1
+fi
+if command -v apt-get &> /dev/null; then
+ apt-get clean
+elif command -v dnf &> /dev/null; then
+ dnf clean all
+elif command -v yum &> /dev/null; then
+ yum clean all
+elif command -v pacman &> /dev/null; then
+ pacman -Scc --noconfirm
+fi
+
+# Clean /tmp and /var/tmp files older than 7 days
+find /tmp -type f -mtime +7 -exec rm -f {} \;
+find /tmp -type d -empty -mtime +7 -exec rmdir {} \;
+find /var/tmp -type f -mtime +7 -exec rm -f {} \;
+echo "Temporary files older than 7 days removed from /tmp and /var/tmp."
+
+echo "Disk cleanup completed."
diff --git a/log_inspect.sh b/log_inspect.sh
new file mode 100644
index 0000000..bef6581
--- /dev/null
+++ b/log_inspect.sh
@@ -0,0 +1,51 @@
+#!/bin/bash
+# log_inspect.sh - Search or tail system log files
+#
+# Copyright (C) 2025 LINUXexpert.org
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation, version 3 of the License.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see .
+#
+# Usage: log_inspect.sh [search | tail ]
+# Description: Searches across /var/log for a pattern, or tails a specific log file.
+
+if [ "$1" = "search" ]; then
+ pattern="$2"
+ if [ -z "$pattern" ]; then
+ echo "Usage: $0 search "; exit 1
+ fi
+ echo "Searching for '$pattern' in /var/log..."
+ grep -R -i --color=auto "$pattern" /var/log 2>/dev/null
+ exit 0
+elif [ "$1" = "tail" ]; then
+ logfile="$2"
+ if [ -z "$logfile" ]; then
+ echo "Usage: $0 tail "; exit 1
+ fi
+ if [ ! -f "$logfile" ]; then
+ echo "Log file '$logfile' not found."; exit 1
+ fi
+ echo "== Last 100 lines of $logfile =="
+ tail -n 100 "$logfile"
+ exit 0
+else
+ # Default: tail the main system log (syslog or messages)
+ if [ -f /var/log/syslog ]; then
+ echo "== Last 50 lines of /var/log/syslog =="
+ tail -n 50 /var/log/syslog
+ elif [ -f /var/log/messages ]; then
+ echo "== Last 50 lines of /var/log/messages =="
+ tail -n 50 /var/log/messages
+ else
+ echo "No syslog or messages log found."
+ fi
+fi
diff --git a/log_rotate.sh b/log_rotate.sh
new file mode 100644
index 0000000..f267c81
--- /dev/null
+++ b/log_rotate.sh
@@ -0,0 +1,38 @@
+#!/bin/bash
+# log_rotate.sh - Compress and remove old log files
+#
+# Copyright (C) 2025 LINUXexpert.org
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation, version 3 of the License.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see .
+#
+# Usage: log_rotate.sh [days]
+# days: rotate logs older than this many days (default 7).
+# Description: Compresses .log files older than X days in /var/log and deletes archives older than 90 days.
+
+DAYS="$1"
+if ! [[ "$DAYS" =~ ^[0-9]+$ ]]; then
+ DAYS=7
+fi
+if [ $EUID -ne 0 ]; then
+ echo "Please run as root to rotate system logs."
+ exit 1
+fi
+
+echo "Rotating logs older than $DAYS days..."
+# Compress uncompressed .log files older than $DAYS days
+find /var/log -type f -name "*.log" -mtime +$DAYS ! -name "*.gz" -exec gzip {} \;
+echo "Compressed logs older than $DAYS days."
+
+# Remove very old compressed logs (older than 90 days)
+find /var/log -type f -name "*.gz" -mtime +90 -exec rm -f {} \;
+echo "Removed log archives older than 90 days."
diff --git a/network_info.sh b/network_info.sh
new file mode 100644
index 0000000..c06350d
--- /dev/null
+++ b/network_info.sh
@@ -0,0 +1,53 @@
+#!/bin/bash
+# network_info.sh - Show network interfaces, routes, open ports, firewall rules
+#
+# Copyright (C) 2025 LINUXexpert.org
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation, version 3 of the License.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see .
+#
+# Usage: network_info.sh (no arguments)
+# Description: Displays network interface addresses, routing table, open ports, and iptables rules.
+
+echo "==== Network Interfaces (IP addresses) ===="
+if command -v ip &> /dev/null; then
+ ip -brief addr show # brief output of interfaces and addresses
+elif command -v ifconfig &> /dev/null; then
+ ifconfig -a
+else
+ echo "No network interface tool (ip or ifconfig) available."
+fi
+
+echo -e "\n==== Routing Table ===="
+if command -v ip &> /dev/null; then
+ ip route show
+elif command -v route &> /dev/null; then
+ route -n
+else
+ echo "No routing tool (ip or route) available."
+fi
+
+echo -e "\n==== Listening Ports (TCP/UDP) ===="
+if command -v ss &> /dev/null; then
+ ss -tulwn # show TCP/UDP ports in listen state with numeric addresses
+elif command -v netstat &> /dev/null; then
+ netstat -tuln
+else
+ echo "No socket listing tool (ss or netstat) available."
+fi
+
+echo -e "\n==== Firewall Rules (iptables) ===="
+if command -v iptables &> /dev/null; then
+ iptables -L -n -v # list firewall rules with numeric addresses and packet counts
+else
+ echo "iptables command not found (no firewall rules to show or using nftables)."
+fi
diff --git a/process_monitor.sh b/process_monitor.sh
new file mode 100644
index 0000000..b7cb3e2
--- /dev/null
+++ b/process_monitor.sh
@@ -0,0 +1,40 @@
+#!/bin/bash
+# process_monitor.sh - Show top processes and allow killing by name or PID
+#
+# Copyright (C) 2025 LINUXexpert.org
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation, version 3 of the License.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see .
+#
+# Usage: process_monitor.sh [kill ]
+# Description: Without args, shows top CPU & memory processes. With "kill", terminates process by name or PID.
+
+if [ "$1" = "kill" ]; then
+ target="$2"
+ if [ -z "$target" ]; then
+ echo "Usage: $0 kill "; exit 1
+ fi
+ # If target is numeric (PID), kill that PID, else kill by name
+ if [[ "$target" =~ ^[0-9]+$ ]]; then
+ kill "$target" && echo "Process $target killed." || echo "Failed to kill process $target."
+ else
+ # Use pkill to kill by name (match full process name)
+ pkill -x "$target" && echo "Processes named '$target' killed." || echo "No process '$target' found or kill failed."
+ fi
+ exit 0
+fi
+
+echo "==== Top 5 CPU-consuming processes ===="
+ps -eo pid,user,comm,%cpu --sort=-%cpu | head -n 6
+
+echo -e "\n==== Top 5 Memory-consuming processes ===="
+ps -eo pid,user,comm,%mem --sort=-%mem | head -n 6
diff --git a/restore.sh b/restore.sh
new file mode 100644
index 0000000..27331c1
--- /dev/null
+++ b/restore.sh
@@ -0,0 +1,45 @@
+#!/bin/bash
+# restore.sh - Restore files from a backup archive
+#
+# Copyright (C) 2025 LINUXexpert.org
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation, version 3 of the License.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see .
+#
+# Usage: restore.sh [target_directory]
+# Description: Extracts the tar.gz archive into the target directory (current dir if not specified).
+
+ARCHIVE="$1"
+TARGET="$2"
+if [ -z "$ARCHIVE" ]; then
+ echo "Usage: $0 [target_directory]"
+ exit 1
+fi
+if [ ! -f "$ARCHIVE" ]; then
+ echo "Backup archive '$ARCHIVE' not found!"; exit 1
+fi
+
+if [ -z "$TARGET" ]; then
+ TARGET="."
+else
+ if [ ! -d "$TARGET" ]; then
+ mkdir -p "$TARGET" || { echo "Failed to create target directory '$TARGET'"; exit 1; }
+ fi
+fi
+
+tar -xzf "$ARCHIVE" -C "$TARGET"
+status=$?
+if [ $status -eq 0 ]; then
+ echo "Restore successful to directory: $TARGET"
+else
+ echo "Restore failed with error code $status"
+fi
diff --git a/security_audit.sh b/security_audit.sh
new file mode 100644
index 0000000..0fa89a7
--- /dev/null
+++ b/security_audit.sh
@@ -0,0 +1,41 @@
+#!/bin/bash
+# security_audit.sh - Check for common security issues (permissions, open ports)
+#
+# Copyright (C) 2025 LINUXexpert.org
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation, version 3 of the License.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see .
+#
+# Usage: security_audit.sh (no arguments)
+# Description: Lists world-writable files/dirs, SUID/SGID files, and listening ports.
+
+# World-writable files (perm bits: others have write)
+echo "==== World-Writable Files (potentially unsafe) ===="
+find / -xdev -type f -perm -0002 -printf '%M %u %g %p\n' 2>/dev/null
+
+# World-writable directories without sticky bit
+echo -e "\n==== World-Writable Directories (no sticky bit) ===="
+find / -xdev -type d -perm -0002 ! -perm -1000 -printf '%M %u %g %p\n' 2>/dev/null
+
+# SUID/SGID files (files with setuid or setgid bits)
+echo -e "\n==== SUID/SGID Files ===="
+find / -xdev \( -perm -4000 -o -perm -2000 \) -printf '%M %u %g %p\n' 2>/dev/null
+
+# Open listening ports
+echo -e "\n==== Listening Network Ports ===="
+if command -v ss &> /dev/null; then
+ ss -tulwn
+elif command -v netstat &> /dev/null; then
+ netstat -tuln
+else
+ echo "No command available to list network ports."
+fi
diff --git a/service_manager.sh b/service_manager.sh
new file mode 100644
index 0000000..31fee02
--- /dev/null
+++ b/service_manager.sh
@@ -0,0 +1,71 @@
+#!/bin/bash
+# service_manager.sh - Start/stop/restart and manage system services
+#
+# Copyright (C) 2025 LINUXexpert.org
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation, version 3 of the License.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see .
+#
+# Usage: service_manager.sh
+# Actions: start, stop, restart, status, enable, disable, list
+# Description: Uses systemctl or service to control services.
+
+action="$1"
+service="$2"
+
+if [ "$action" = "list" ]; then
+ # List running services
+ if command -v systemctl &> /dev/null; then
+ systemctl list-units --type=service --state=running
+ elif command -v service &> /dev/null; then
+ service --status-all 2>&1 | grep '+' # shows running services with [+]
+ else
+ echo "No service management tool available."
+ fi
+ exit 0
+fi
+
+if [ -z "$action" ] || [ -z "$service" ]; then
+ echo "Usage: $0 {start|stop|restart|status|enable|disable|list} "
+ exit 1
+fi
+
+if command -v systemctl &> /dev/null; then
+ case "$action" in
+ start|stop|restart|status)
+ systemctl $action "$service"
+ ;;
+ enable|disable)
+ systemctl $action "$service"
+ ;;
+ *)
+ echo "Invalid action. Use start, stop, restart, status, enable, disable, or list."
+ exit 1
+ ;;
+ esac
+elif command -v service &> /dev/null; then
+ case "$action" in
+ start|stop|restart)
+ service "$service" $action
+ ;;
+ status)
+ service "$service" status
+ ;;
+ *)
+ echo "Action '$action' not supported with legacy service command."
+ exit 1
+ ;;
+ esac
+else
+ echo "No known service manager found (systemctl/service)."
+ exit 1
+fi
diff --git a/sys_monitor.sh b/sys_monitor.sh
new file mode 100644
index 0000000..19e86ac
--- /dev/null
+++ b/sys_monitor.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+# sys_monitor.sh - System resource monitoring script
+#
+# Copyright (C) 2025 LINUXexpert.org
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation, version 3 of the License.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see .
+#
+# Usage: sys_monitor.sh (no arguments)
+# Description: Prints system uptime, memory, disk usage, and top CPU/mem processes.
+
+echo "==== System Uptime and Load ===="
+uptime
+
+echo -e "\n==== Memory Usage ===="
+free -h
+
+echo -e "\n==== Disk Usage ===="
+# Exclude temporary filesystems (tmpfs) for clarity
+df -h -x tmpfs -x devtmpfs
+
+echo -e "\n==== Top 5 Processes by CPU Usage ===="
+# Display header and top 5 CPU-consuming processes
+ps -eo pid,user,comm,%cpu --sort=-%cpu | head -n 6
+
+echo -e "\n==== Top 5 Processes by Memory Usage ===="
+ps -eo pid,user,comm,%mem --sort=-%mem | head -n 6
diff --git a/update_system.sh b/update_system.sh
new file mode 100644
index 0000000..5888d9b
--- /dev/null
+++ b/update_system.sh
@@ -0,0 +1,48 @@
+#!/bin/bash
+# update_system.sh - Apply system package updates
+#
+# Copyright (C) 2025 LINUXexpert.org
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation, version 3 of the License.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see .
+#
+# Usage: update_system.sh (no arguments, run as root)
+# Description: Detects the Linux distro's package manager and installs all updates.
+
+# Ensure running as root
+if [ "$EUID" -ne 0 ]; then
+ echo "Please run as root to apply system updates."
+ exit 1
+fi
+
+if command -v apt-get &> /dev/null; then
+ echo "Updating with apt-get..."
+ apt-get update && apt-get upgrade -y
+elif command -v apt &> /dev/null; then
+ echo "Updating with apt..."
+ apt update && apt upgrade -y
+elif command -v dnf &> /dev/null; then
+ echo "Updating with dnf..."
+ dnf upgrade -y
+elif command -v yum &> /dev/null; then
+ echo "Updating with yum..."
+ yum update -y
+elif command -v zypper &> /dev/null; then
+ echo "Updating with zypper..."
+ zypper refresh && zypper update -y
+elif command -v pacman &> /dev/null; then
+ echo "Updating with pacman..."
+ pacman -Syuu --noconfirm
+else
+ echo "Error: No supported package manager found on this system."
+ exit 1
+fi
diff --git a/user_manage.sh b/user_manage.sh
new file mode 100644
index 0000000..fdcf82a
--- /dev/null
+++ b/user_manage.sh
@@ -0,0 +1,76 @@
+#!/bin/bash
+# user_manage.sh - User and Group Management Script
+#
+# Copyright (C) 2025 LINUXexpert.org
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation, version 3 of the License.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see .
+#
+# Usage: user_manage.sh [arguments...]
+# Subcommands: adduser , deluser , addgroup , delgroup ,
+# addtogroup , lock , unlock ,
+# listusers, listgroups
+# Description: Automates user/group creation, deletion, and modifications.
+# Requires root privileges for most operations.
+
+subcmd="$1"
+case "$subcmd" in
+ adduser)
+ user="$2"
+ if [ -z "$user" ]; then echo "Username required. Usage: $0 adduser "; exit 1; fi
+ # Create user with a home directory (-m) and default settings
+ useradd -m "$user" && echo "User '$user' created." || echo "Failed to create user."
+ ;;
+ deluser)
+ user="$2"
+ if [ -z "$user" ]; then echo "Username required. Usage: $0 deluser "; exit 1; fi
+ # Delete user and remove home directory (-r)
+ userdel -r "$user" && echo "User '$user' deleted." || echo "Failed to delete user."
+ ;;
+ addgroup)
+ group="$2"
+ if [ -z "$group" ]; then echo "Group name required. Usage: $0 addgroup "; exit 1; fi
+ groupadd "$group" && echo "Group '$group' created." || echo "Failed to create group."
+ ;;
+ delgroup)
+ group="$2"
+ if [ -z "$group" ]; then echo "Group name required. Usage: $0 delgroup "; exit 1; fi
+ groupdel "$group" && echo "Group '$group' deleted." || echo "Failed to delete group."
+ ;;
+ addtogroup)
+ user="$2"; group="$3"
+ if [ -z "$user" ] || [ -z "$group" ]; then
+ echo "Usage: $0 addtogroup "; exit 1;
+ fi
+ usermod -aG "$group" "$user" && echo "Added user '$user' to group '$group'." || echo "Failed to modify group membership."
+ ;;
+ lock)
+ user="$2"
+ if [ -z "$user" ]; then echo "Username required. Usage: $0 lock "; exit 1; fi
+ usermod -L "$user" && echo "User '$user' account locked." || echo "Failed to lock account."
+ ;;
+ unlock)
+ user="$2"
+ if [ -z "$user" ]; then echo "Username required. Usage: $0 unlock "; exit 1; fi
+ usermod -U "$user" && echo "User '$user' account unlocked." || echo "Failed to unlock account."
+ ;;
+ listusers)
+ cut -d: -f1 /etc/passwd
+ ;;
+ listgroups)
+ cut -d: -f1 /etc/group
+ ;;
+ *)
+ echo "Usage: $0 {adduser|deluser|addgroup|delgroup|addtogroup|lock|unlock|listusers|listgroups}"
+ exit 1
+ ;;
+esac