Shell Scripting - User Management

User Management challenge

User account management using a shell script involves automating tasks like creating, deleting, listing, and resetting user accounts. The script takes different command-line options (-c, -d, -l, -r, -h) to perform these actions. The process includes verifying if a user exists before making changes, prompting the user for necessary inputs, and providing feedback messages for successful or failed operations.

Task 1

Account Creation:

  1. Introduce an option -c or --create to enable the script to establish a new user account. The script should solicit the username and password from the user.

  2. Verify the availability of the username before proceeding with the account creation. If the username is already in use, show a relevant message and exit the script smoothly.

  3. Upon successful account creation, present a confirmation message displaying the newly created username.

Task 2

Account Deletion:

  1. Introduce an option -d or --delete to allow the script to remove an existing user account. The script should ask the user to provide the username of the account that is to be deleted.

  2. Confirm the existence of the username before attempting to delete the account. If the username does not exist, show a relevant message and exit the script smoothly.

  3. After successfully deleting the account, present a confirmation message displaying the deleted username.

Task 3

Password Reset:

  1. Add an option -r or --reset to enable the script to update the password for an existing user account. The script should request the username and the new password from the user.

  2. Verify if the username exists before proceeding to reset the password. If the username is not found, show a relevant message and exit the script gracefully.

  3. Upon successfully resetting the password, display a confirmation message that includes the username and the new password.

Task 4

List User Accounts:

  1. Introduce an option -l or --list to enable the script to display all user accounts on the system. The script should present the usernames along with their respective user IDs (UID).

Task 5

Help and Usage Information:

  1. Add an option -h or --help to the script that provides usage instructions and lists the available command-line options.

Below is the shell script created to handle the above tasks.

The relevant parameters can be passed in order to handle the desired Tasks

For Example: For Account creation: -c or —create,

for Account deletion -d or —delete and so on.

In order to create the script it has to be in .sh file format and to execute the script, we need to give it execute permission.

Once the execute permission is granted we can run the below command to execute

sudo ./user_managment.sh -c for Create Username

You may refer to the below script used for accomplishing these Tasks

user_management.sh

Shell scripting offers a powerful way to streamline user account management tasks on UNIX and Linux systems. By leveraging the flexibility of shell scripts, administrators can automate processes like creating, deleting, listing, and resetting user accounts with ease. These scripts can interact with system files, prompt for user input, and perform checks to ensure the smooth execution of commands.

For instance, scripts can include options to verify if a username exists before creating or deleting accounts, thereby preventing errors and ensuring efficient management. Additionally, shell scripts can be designed to provide informative feedback and confirmation messages, enhancing the overall user experience.

By automating these repetitive tasks, administrators can save time, reduce the risk of human error, and maintain better control over system user accounts.