This is an enhanced Bash script for managing users in a Linux environment, specifically tailored for enterprise use. It provides a robust set of features for creating, modifying, and deleting users, as well as managing user groups and enforcing strong password policies. The script is designed to be secure, user-friendly, and compliant with enterprise standards.
- User Creation:
- Create new users with a choice of shell (
bashorzsh). - Enforces strong password policies:
- Minimum 8 characters.
- Requires uppercase letters, numbers, and special characters.
- Create new users with a choice of shell (
- User Deletion:
- Delete users along with their associated groups and home directories.
- Confirmation prompt to prevent accidental deletions.
- User Modification:
- Lock/Unlock Users: Temporarily disable or enable user accounts.
- Change Passwords: Securely change user passwords with strong password enforcement.
- Change Primary Group: Modify the primary group of a user, with the option to create new groups if they don't exist.
- User Listing:
- List all users with their details, including:
- User ID (UID)
- Group ID (GID)
- Home directory
- Login shell
- List all users with their details, including:
-
Logging:
- All actions are logged to
/var/log/user_management.logfor audit purposes. - Logs include timestamps, event types (e.g., SUCCESS, ERROR), and detailed messages.
- All actions are logged to
-
User Experience:
- Interactive prompts for user input.
- Loading animations for better feedback during operations.
Important
Before running the script, you must convert the file to Linux Line Feeding because Carriage Return characters like \r is causing errors, and it might be invisible in your text editor.
To resolve this error you must run dos2unix User_management.sh, it removes all the unwanted (CRLF) characters.
To use the script, simply execute it in a Bash shell:
sudo ./User_management.shNote: The script requires root privileges to perform user management tasks.
The script provides a menu-driven interface with the following options:
- 1. Add User: Create a new user with a strong password and a choice of shell.
- 2. Remove User: Delete a user, their group, and home directory.
- 3. Modify User: Modify user attributes (lock/unlock, change password, change primary group).
- 4. List Users: Display a list of all users with their details.
- 0. Exit: Exit the script.
All actions performed by the script are logged to /var/log/user_management.log. This log file is created automatically if it doesn't exist, and it includes timestamps and event details for auditing purposes.
- Select option 1 from the main menu.
- Enter the username and a strong password (minimum 8 characters, with uppercase, numbers, and special characters).
- Choose the login shell (
bashorzsh). - The user is created, and the action is logged.
- Select option 2 from the main menu.
- Enter the username to delete.
- Confirm the deletion.
- The user, their group, and home directory are removed, and the action is logged.
- Select option 3 from the main menu.
- Choose from the following sub-options:
- Lock/Unlock User: Temporarily disable or enable a user account.
- Change Password: Update the user's password with strong password enforcement.
- Change Primary Group: Modify the user's primary group, with the option to create a new group if it doesn't exist.
- The changes are applied, and the action is logged.
- Select option 4 from the main menu.
- A table of all users is displayed, showing their UID, GID, home directory, and login shell.
- Strong Password Enforcement: Ensures all passwords meet enterprise security standards.
- Audit Logging: All actions are logged for compliance and security auditing.
- Confirmation Prompts: Prevents accidental deletions or modifications.
The log file (/var/log/user_management.log) records all actions with timestamps and event types. Here's an example of what the log might look like:
[01-Oct-2023 14:30:45] [SUCCESS] New user 'john' created in BASH shell
[01-Oct-2023 14:31:10] [ERROR] Failed to change the password of user 'john'
[01-Oct-2023 14:32:00] [INFO] The 'developers' group is now the group owner of all the files owned by 'john'
- Bash Shell: The script is written for Bash and should be run in a Bash environment.
- Root Privileges: The script requires root access to perform user management tasks.
- Linux Environment: Designed for Linux systems with standard user management tools (
useradd,usermod,userdel, etc.).
Contributions are welcome! If you'd like to improve this script, feel free to:
- Fork the repository.
- Make your changes.
- Submit a pull request.
Enjoy managing users with this powerful and secure script! 🚀





