That's a very practical question! Beyond usermod, passwd, and grep which you've used, there are several essential commands for managing user accounts in Linux.
Here's a list of some common user account management commands and what they're generally used for:
-
useradd:- Purpose: Used to create a new user account.
- Example:
sudo useradd newuser(This creates the user but usually doesn't create a home directory or set a password automatically, depending on the system's default configuration). - Common options:
-m: Create the user's home directory if it doesn't exist.-s: Specify the default shell for the user (e.g.,/bin/bash).-g: Specify the primary group.-G: Specify supplementary groups.
-
userdel:- Purpose: Used to delete a user account.
- Example:
sudo userdel olduser - Common options:
-r: Remove the user's home directory and mail spool along with the account. Use with caution!
-
passwd: (You've seen this one in the context of locking/unlocking, but its primary use is for passwords!)- Purpose: Used to change a user's password, or to lock/unlock an account.
- Example:
sudo passwd username(prompts for a new password) - Common options:
-l: Lock the password for an account.-u: Unlock the password for an account.-e: Force password expiration on a user's next login.-d: Delete the password for an account (makes passwordless login possible if not restricted otherwise).
-
usermod: (You've used this to change the home directory)- Purpose: Used to modify user account properties after creation.
- Example:
sudo usermod -d /new/home newuser - Common options:
-d: Change the user's home directory.-s: Change the user's default shell.-g: Change the primary group.-G: Add or change supplementary groups.-l: Change the login name of the user.-L: Lock the user's account (similar topasswd -l).-U: Unlock the user's account (similar topasswd -u).
-
id:- Purpose: Displays user and group information for the current user or a specified user.
- Example:
id labex
-
groups:- Purpose: Shows the groups a user belongs to.
- Example:
groups labex
-
chage:- Purpose: Used to change user password expiry information. This is for more advanced password policies.
- Example:
sudo chage -l username(list password aging information)
-
gpasswd:- Purpose: Administers
/etc/groupand/etc/gshadow. Used to add or remove users from groups, or modify group passwords. - Example:
sudo gpasswd -a newuser sudo(addsnewuserto thesudogroup)
- Purpose: Administers
These commands, used in conjunction, give you comprehensive control over user accounts and their associated properties on a Linux system.
Is there any specific user management task you're curious about, or would you like to know more about any of these commands in particular?