The Wayback Machine - https://web.archive.org/web/20240706113520/https://www.geeksforgeeks.org/useradd-command-in-linux-with-examples/
Open In App

How to add User in Linux | useradd Command

Last Updated : 22 Dec, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

useradd is a command in Linux that is used to add user accounts to your system. It is just a symbolic link to adduser command in Linux and the difference between both of them is that useradd is a native binary compiled with the system whereas adduser is a Perl script that uses useradd binary in the background. It makes changes to the following files:

  • /etc/passwd
  • /etc/shadow
  • /etc/group
  • /etc/gshadow
  • creates a directory for new user in /home

Syntax of `useradd` command in Linux

The basic syntac for the `useradd` command is as follows.

useradd [options] [User_name]

Working with `useradd` Command

1. How to Add a User in Linux

This command will add the user named “test_user”.

sudo useradd test_user

2. How to Add User by Specifying a home directory path for the new user

To give a home directory path for new users, we use the following command in Linux.

sudo useradd -d /home/test_user test_user

This will set the home directory of the us”/home/test_user”.

3. How to Create a User with a Specific User ID (UID)

To create a new user with a custom UID, we use the following command.

sudo useradd -u 1234 test_user

This will create a new user with the user-id “1234” and the name “test_user”.

4. How to Create a User with a Specific Group ID (GID)

To create a new user and assign a specific group ID, use the following command

sudo useradd -g 1000 test_user

This will create a new user with the group id “1000” and the name “test_user”.

5. How to Create a User Without a Home Directory

To create a user without a home directory, we use the following command.

sudo useradd -M test_user

This will create the user with the name “test_user” and that too without a home directory.

6. How to Create User with an Expiry Date

To set an expiry date for a user account, we use the following command.

sudo useradd -e 2020-05-30 test_user

This will create the user named “test_user” with the expiry date of 30th May 2020.

7. How to Create User with a Comment

To add a comment or description for a user, we use the following command.

sudo useradd -c "This is a test user" test_user

This will create a user with a short comment or description of the user.

8. How to Create a User with Changed Login Shell

To create a user with a different login shell, we use the following command.

sudo useradd -s /bin/sh test_user

This will create a user named “test_user” with the default shell /bin/sh.

9. How to Set an Unencrypted Password for the User

To set an unencrypted password for the user, we use the following command.

sudo useradd -p test_password test_user

This will create a new user with the name “test_user” and an unencrypted password “test_password”.

10. Displaying Help

To display help, we use the following command.

sudo useradd --help

This command will display the help section of the useradd command.

Conclusion

In this article we have discussed the `useradd` command in Linux which is a powerful tool for creating user accounts with various customizations. Overall, we can say that by understanding its options and syntax, system administrators can efficiently manage user accounts on their Linux system.


Previous Article
Next Article

Similar Reads

Manually Add a User Without Tools Like useradd and adduser in Linux
Adding a user manually in Linux without using tools like useradd or adduser involves modifying system files directly. This method is not recommended for regular use, as it requires careful editing of system files and can lead to errors if not done correctly. However, in some situations, such as when these tools are not available or not working, it
9 min read
How to Change User Password in Linux | passwd Command
Securing user accounts is a fundamental aspect of maintaining a robust and secure Linux system. One essential task is changing user passwords regularly to prevent unauthorized access. The passwd command in Linux provides a straightforward and effective way to modify user passwords. This article will guide you through the process of changing user pa
7 min read
How to Delete User in Linux | userdel Command
Managing user accounts is an essential aspect of Linux system administration. Whether you need to remove an unused account, revoke access for a departing employee, or clean up your system for security reasons, understanding how to delete a user in Linux is a crucial skill. In this guide, we will explore the userdel command, a powerful tool in Linux
6 min read
Ccat – Colorize Cat Command Output command in Linux with Examples
ccat is a command-line tool for Linux and OSX, which is similar to the cat command in Linux. But the difference between cat and ccat is that the ccat shows the content of the file with the syntax highlighted. Currently, ccat supports the following programming languages. JavaScriptJavaRubyPythonGoCJSONInstallation of Ccat First, we are going to see
2 min read
How to Display Command History in Linux | history Command
The command-line interface in Linux provides powerful tools for users, and mastering command history is essential for efficient navigation and retrieval of previously executed commands. The history command is a valuable utility that allows users to view and search through their command history. In this comprehensive guide, we will explore the vario
4 min read
How to Add User to a Group in Linux
A group in Linux is a way to put users with similar access and permissions in a collection. By using groups, an administrator can define access control and permissions for all the users belonging to that group. Without groups, the administrator would have to define roles for individual users however, with groups those roles can be given to a group
7 min read
GithubFind3r - Fast Command Line Repo/User/Commit Search Tool
GithubFind3r is an automated tool developed in Node JS which is a CLI-based tool used to get information about the Repositories, Commits, and information about the Users from GitHub. GithubFind3r is available on GitHub, it's free and open-source to use. The GithubFind3r tool displays the results in a more sophisticated and more attractive manner. N
2 min read
How to create a Shared Folder between two Local User in Linux?
This article shows how to set-up a shared folder between two local users in Linux. The shared directory/folder will be accessible to both the users, they will be able to read/write each other's file. Let us create shared directory /home/shareFolder for user Bob and Alice and add them to a common group named projectA. Note: You can create the uses B
2 min read
Configure Passwordless Sudo For A Specific User in Linux
Linux has a tough permission rule. Being a root user you are permitted to do anything however the normal user has only some allowed permissions. To run many other commands, they required to ask permissions from the superuser, using keyword sudo after which they need to enter the password. This requirement of the password after sudo command can be r
1 min read
User Management in Linux
A user is an entity, in a Linux operating system, that can manipulate files and perform several other operations. Each user is assigned an ID that is unique for each user in the operating system. In this post, we will learn about users and commands which are used to get information about the users. After installation of the operating system, the ID
4 min read