A collection of bash scripts for Linux system administration, focusing on user account management, monitoring, and remote command execution.
Creates a new user account with an automatically generated password.
Features:
- Requires superuser privileges
- Generates secure random passwords
- Forces password change on first login
- Displays username, password, and hostname
Usage:
sudo ./add-local-user.sh USERNAME [COMMENT]Example:
sudo ./add-local-user.sh jsmith "John Smith - Developer"Disables, deletes, and/or archives user accounts on the local system.
Features:
- Multiple operation modes (disable, delete, archive)
- Protection against system account deletion (UID < 1000)
- Optional home directory archiving
- Bulk user processing
Options:
-d- Delete accounts instead of disabling-r- Remove home directory when deleting-a- Create archive of home directory
Usage:
sudo ./disable-local-user.sh [-dra] USERNAME [USERNAME2...]Example:
# Disable a user
sudo ./disable-local-user.sh jsmith
# Delete user and remove home directory
sudo ./disable-local-user.sh -d -r jsmith
# Archive home directory then delete
sudo ./disable-local-user.sh -a -d jsmithExecutes commands on multiple remote servers via SSH.
Features:
- Dry run mode for testing
- Verbose output option
- Custom server list file
- Sudo support for remote commands
- Error handling and reporting
Options:
-f FILE- Specify custom server list file (default: /vagrant/servers)-n- Dry run (display commands without executing)-s- Execute with sudo on remote servers-v- Verbose mode (show server names)
Usage:
./run-anywhere.sh [-f FILE] [-nsv] COMMANDExample:
# Check uptime on all servers
./run-anywhere.sh uptime
# Update package lists with sudo
./run-anywhere.sh -s "apt update"
# Dry run with verbose output
./run-anywhere.sh -n -v "hostname"Analyzes login attempts and identifies potential attackers based on failed login counts.
Features:
- Parses system log files for failed login attempts
- Groups failures by IP address
- Provides geolocation information
- Configurable threshold for alerts
Requirements:
geoiplookupcommand (install with:apt install geoip-bin)- System log file with authentication entries
Usage:
./show-attackers.sh LOG_FILEExample:
./show-attackers.sh /var/log/auth.logOutput:
Count, IP, Location
15, 192.168.1.100, United States
12, 10.0.0.50, Unknown
- Linux system (CentOS/RHEL 7+ recommended)
- Root/sudo access for user management operations
- SSH access configured for remote execution scripts
geoiplookupcommand (for show-attackers.sh)
- Clone the repository:
git clone https://github.com/uv012/linux-user-management-scripts.git
cd linux-user-management-scripts
2. Make scripts executable:
```bash
chmod +x *.sh- For
run-anywhere.sh, create a servers file:
echo "server1.example.com" > /vagrant/servers
echo "server2.example.com" >> /vagrant/servers- All user management scripts require root privileges
- Passwords are displayed only once during account creation
- System accounts (UID < 1000) are protected from deletion
- SSH connections use timeout to prevent hanging
- Scripts include error handling and validation
- Each script includes comprehensive error checking:
- Input validation
- Privilege verification
- Command execution status checking
- Meaningful error messages
- Appropriate exit codes
Feel free to submit issues and enhancement requests!
This project is open source and available under the MIT License.