The useradd
command is used in Linux systems to create a new user account. It allows system administrators to add users to the system, set their home directories, and configure various user settings.
The basic syntax of the useradd
command is as follows:
useradd [options] [username]
-m
: Create the user’s home directory if it does not exist.-d
: Specify the home directory for the new user.-s
: Set the login shell for the new user.-G
: Add the user to specified supplementary groups.-c
: Provide a comment or description for the user account.-e
: Set an expiration date for the user account.useradd -m newuser
useradd -d /home/customuser -m customuser
useradd -s /bin/bash newuser
useradd -G sudo,developers newuser
useradd -c "John Doe, Developer" johndoe
useradd -e 2023-12-31 expireduser
-m
option to ensure that a home directory is created for the new user.-s
option to set a preferred shell, especially if the user will be using the command line frequently.-G
option for appropriate permissions.passwd
command.