Linux – useradd Command

The useradd command is used to create new user accounts in Linux. This command allows system administrators to quickly and easily add new users, set up their home directories, and define their default settings.



Tutorials dojo strip

Initial Example

To create a new user account named john, you would use:

useradd josh




USERADD Parameters

ParameterDescription
-b, --base-dir BASE_DIRSpecify the base directory for the user’s home directory if the -m option is used.
-c, --comment COMMENTAdd a comment (usually the user’s full name) to the new user account.
-d, --home HOME_DIRSpecify the home directory for the new user account.
-D, --defaultsDisplay or change the default values for user creation.
-e, --expiredate EXPIRE_DATESet the account expiry date in YYYY-MM-DD format.
-f, --inactive INACTIVESet the number of days after a password expires until the account is permanently disabled.
-g, --gid GROUPSet the primary group for the new user account.
-G, --groups GROUPSSpecify a comma-separated list of supplementary groups for the new user account.
-k, --skel SKEL_DIRSpecify an alternative skeleton directory to use when creating the user’s home directory.
-K, --key KEY=VALUEOverride /etc/login.defs defaults.
-l, --no-log-initDo not add the user to the lastlog and faillog databases.
-m, --create-homeCreate the user’s home directory if it does not exist.
-MDo not create the user’s home directory, even if the default behavior is to create it.
-N, --no-user-groupDo not create a user group for the new user account.
-o, --non-uniqueAllow the creation of a user with a non-unique user ID (UID).
-p, --password PASSWORDSet the initial password for the new user account.
-r, --systemCreate a system account instead of a regular user account.
-s, --shell SHELLSpecify the login shell for the new user account.
-u, --uid UIDSet the user ID (UID) for the new user account.
-U, --user-groupCreate a group with the same name as the user account.
-Z, --selinux-user SEUSERSpecify the SELinux user for the new user account.
--helpDisplay help information and exit.
--versionDisplay version information and exit.




Examples

1. Creating a User with a Home Directory

To create a new user and automatically create a home directory, use the -m option:

useradd -m josh

2. Specifying the User’s Shell

To create a new user with a specific login shell, use the -s option:

useradd -s /bin/bash josh

3. Setting the User’s UID and GID

To create a new user with a specific user ID (UID) and group ID (GID), use the -u and -g options:

useradd -u 1001 -g 100 josh

4. Adding the User to Supplementary Groups

To add the new user to supplementary groups, use the -G option:

useradd -G wheel,developers josh

5. Setting an Expiry Date for the User Account

To set an expiry date for the user account, use the -e option followed by the date in YYYY-MM-DD format:

useradd -e 2025-12-31 josh




Linux Playground

Scroll to Top