The user_adm.sh script performs several common user management tasks. The usage() text explains how to use the script when the user provides incorrect parameters or includes the -usage parameter. A case statement parses command arguments and executes the appropriate commands.
The valid command options for the user_adm.sh script are: -adduser, -deluser, -shell, -disable, -enable, -expiry, -passwd, -newgroup, -delgroup, -addgroup, -details, and -usage. When the *) case is matched, it means no option was recognized; hence, usage() is invoked.
Run this script as the root. It confirms the user ID (the root's user ID is 0) before the arguments are examined.
When an argument is matched, the [ $# -ne 3 ] && test usage checks the number of arguments. If the number of command arguments does not match the required number, the usage() function is invoked and the script exits.
These options are supported by the following scripts:
- -useradd: The useradd command creates a new user:
useradd USER -p PASSWORD -m
- The -m option creates the home directory.
- -deluser: The deluser command removes the user:
deluser USER --remove-all-files
- The --remove-all-files option removes all the files associated with the user, including the home directory.
- -shell: The chsh command changes the default shell of the user:
chsh USER -s SHELL
- -disable and -enable: The usermod command manipulates several attributes related to user accounts. usermod -L USER locks the user account and usermod -U USER unlocks the user account.
- -expiry: The change command manipulates user account expiry information:
chage -E DATE
These options are supported:
- -m MIN_DAYS: This sets the minimum number of days between password changes to MIN_DAYS
-
- -M MAX_DAYS: This sets the maximum number of days during which a password is valid
- -W WARN_DAYS: This sets the number of days to provide a warning before a password change is required
- -passwd: The passwd command changes a user's password:
passwd USER
The command will prompt to enter a new password:
- -newgroup and -addgroup: The addgroup command adds a new user group to the system:
addgroup GROUP
If you include a username, it will add this user to a group:
addgroup USER GROUP
-delgroup
The delgroup command removes a user group:
delgroup GROUP
- -details: The finger USER command displays user information, including the home directory, last login time, default shell, and so on. The chage -l command displays the user account expiry information.