Creating a New User
The primary command to add a new local user isuseradd. System administrators typically use this command to add new users. For example, to create a new user named Bob, execute:
/home/bob (based on the system’s default configuration) and his login shell is set to /bin/sh.
To set a password for Bob’s account, use the passwd command:
Both
useradd and passwd commands must be executed with root privileges.whoami command. Additionally, users can change their password at any time by simply running passwd without any additional arguments.
Using Options with useradd
Theuseradd command supports several options that allow you to customize the user creation process. Here are some commonly used options:
- -u: Specify a custom UID.
- -g: Specify the primary group via a custom GID.
- -d: Define a custom home directory path.
- -s: Set the default login shell.
- -c: Add a comment (often used for a user description).
- -e: Set the account expiration date.
- -G: Add the new user to additional (secondary) groups.
/home/robert, selects /bin/bash as his login shell, and includes the comment “Mercury Project member” in his account information.
You can validate Bob’s settings with the id command:
/etc/passwd file to verify the custom comment and other account details:
User Deletion and Group Management
To delete a user account, use theuserdel command followed by the username:
-
Adding a New Group: Use the
groupaddcommand. The -g option lets you specify a custom GID. -
Deleting a Group: Use the
groupdelcommand along with the group name.
Hands-On Practice
We recommend practicing these Linux user account management commands on your local system to reinforce your skills in system administration.