Linux is a multi-user operating system kernel that allows multiple users to operate on the same machine. For this to happen, we need some way to add newly authenticated users to the system. useradd is the Linux command line utility that allows us to do this task.
In this article, we will discuss various examples and options of the useradd command.
useradd Command in Linux
In Linux, the useradd command is used to add user accounts to your system. It's merely a symbolic link to the Linux adduser command; the only difference is that useradd is a native binary compiled with the system, whereas adduser is a Perl script that utilizes the useradd binary in the background.
The syntax for this command is
$ useradd [options] username
1. Create a basic user
$ sudo useradd test_user
2. To assign a new user's home directory path
$ sudo useradd -d /home/test_user test_user
3. Create a user with a unique id.
$ sudo useradd -u 1234 test_user
4. Make a user with a unique group id.
$ sudo useradd -g 1000 test_user
5. To establish a user without a home directory.
$ sudo useradd -M test_user
6. Make a user with an expiration date.
$ sudo useradd -e 2020-05-30 test_user
7. To create a user with a comment
$ sudo useradd -c "This is a test user" test_user
8. To provide the user an unencrypted password
$ sudo useradd -p test_password test_user
9. Create a user with a different login shell.
$ sudo useradd -s /bin/sh test_user
10. To display help
$ sudo useradd --help
Conclusion
In this article, we went through various options related to the useradd command in Linux. We saw how this command line utility could be used to create passwords for users, create users with expiration dates, create users with unique IDs, get command manuals, etc.
People are also reading:
Leave a Comment on this Post