Introduction Show
Linux is a multiuser environment, and user provisioning is an essential responsibility in system management. System administrators add, delete, and manage users and groups on the system. The This article shows how to create and add users in Linux. Prerequisites
useradd Command SyntaxThe basic syntax for the
Running the command creates a new user account or updates an existing user according to the values in:
The default values vary between different systems. The rules limit the username to:
The regular expression for checking the username validity is:
Note: Debian follows a different set of rules for usernames. However, the provided rules are a good starting point for all systems to help avoid problems. In addition, the command also creates a group for the new user. Adding a new user requires sudo permissions to modify the files for storing user and group information. useradd Command OptionsThe
Creating New Users in LinuxCreating new users in Linux does the following: 1. Provides a unique UID and GID.
Note: Numbers vary between different operating systems. The example values are for Ubuntu. 2. Edits files that store account information.
3. Sets user permissions on the home directory through the group. Follow the examples below to see how to add users in Linux. Adding a User in LinuxTo add a user in Linux, run the following command in the terminal:
If prompted, enter the sudo password to continue. Without any options, the
The command prompts to enter and confirm the password. After creating a password, a new entry appears automatically in the /etc/passwd file. To see the information, view the file with the cat command and grep for the user:
The fields are in the following format:
The Adding a User in Linux and Creating Home DirectoryBy default, the To create a user and the home directory automatically, use the
Check if the directory exists with the ls command:
The directory contains initialization files copied from the /etc/skel directory. Adding a User with a Specific Home DirectoryTo add a user in Linux with a specific home directory, use the
The Adding a User without Home DirectoryIf the /etc/login.defs configuration To override the default settings and add a user without a home directory, use the
The command adds the user without creating a home directory, overriding the default settings. Adding a User with Specific User IDTo add a user with a specific user ID, use the
If the UID is not unique, the terminal outputs a message and does not add the user. Check the UID with the
Use a UID above 1000 to indicate a regular user. Adding a User with Specific Group IDTo create a user and add them to a specific group, use the
The group name or GID must exist. Otherwise, the command throws an error. Check the user's GID with:
The output prints the user's group ID. Adding a User to Multiple GroupsAdd a user to multiple groups with the
Check the user's groups with:
The groups must exist, and the list should not contain any spaces. The command doesn't add the user if any groups do not exist. Adding a User with a Specific Login ShellEach new user gets a default login shell (such as the Bourne shell or Bourne Again Shell). To explicitly define
the user's shell, add the
For example, to add a user and set Bash as the default login shell, run:
Check the /etc/passwd file to confirm the shell selection:
The final field shows the login shell for the new user. Adding a User with a Specific CommentTo add a user with a specific comment, run:
To view the comment, check the /etc/passwd file and grep for the user:
The comment is for descriptive purposes only and has no actual functionality. Adding a User with Account Expiry DateAdd a user with an account expiry date to automatically delete the account after provided date:
View the account's expiry information with:
The output prints the account expiry date
( Adding a User with a Deactivation PeriodIf a user has a password expiry set, the Use the
For example, to have an account deactivate three days after the password expires, run:
View the expiry information with:
The /etc/shadow file stores password information, including idle time (third to the last field). Use this method to deactivate users who don't change their password in the provided timeframe. The deactivation period is a good security measure, and the recommended duration is 35 days. Business requirements dictate what's the perfect duration before the account expires. If the value is too low, the consequences are costly for an administrator, whereas a high value impacts security. Adding a System UserPrograms and systems create system user accounts, which are different from regular users. Programs such as MySQL or Tomcat require a unique user account to work on the system, and daemons typically create system users during installation. To create a system user, use the
Check the user's information with:
The user has a UID lower than 1000, indicating it's a system user. The adduser CommandThe To add a user, run:
The command prints the user and group to the console. Next, the command asks for the following:
Press Y to complete the process. In case of a mistake, press N and reenter the correct information. Check the parameters from the
The command adds all the values entered during the command execution and the Bash shell by default. Add Multiple UsersThe For example, to add ten users, do the following: 1. Create a text file using a text editor:
2. Append usernames to the file, entering each on a new line. For example:
Save the file and close nano (CTRL+X, Y, then Enter). 3. Use a
4. Show the created users with:
To add passwords, exchange the command in the Conclusion After completing this guide, you know how to add new users to a Linux system with the Next, read about privileged access management and how it helps reduce security attacks and data breaches. What is user home directory in Linux?In computing, a home directory is a directory which contains the personal files of a particular user of the system. On Unix/Linux systems, this includes configuration files (usually hidden, i.e. starting with a .), documents, locally installed programs, etc.
Is the home directory where Linux creates user directories?The Linux home directory is a directory for a particular user of the system and consists of individual files. It is also referred to as the login directory. This is the first place that occurs after logging into a Linux system. It is automatically created as "/home" for each user in the directory'.
How to create Linux user without home directory?Without a Home Directory flag. $ useradd -M <username>. $ useradd --no-create-home <username>. $ sudo useradd Ivan.. $ sudo passwd Ivan.. $ su - Ivan.. |