Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
May 29, 2022 07:35 am GMT

useradd vs adduser: Which command to use?

Linux is amazing! Let me tell you what made me say so.

There are multiple ways to perform a function in Linux. Let's say you simply want to print "Hello World" to the screen. To do so, some beginners might create a new file, write "Hello world" to it and then use the cat command to print the contents of the file. Some experienced users may use the echo command to print the same to the screen. Both of them are correct as the job is done perfectly but the only difference is that using the echo command, we can accomplish the job quickly.

In this blog, we are going to discuss about one such function of creating a new user using two commands adduser and useradd. We'll also talk about which command you must use and when.

Let's dive right into it.

adduser command

The adduser command creates a new user on a linux system. Apart from this it does the following things:

  • Creates a new group.
  • Creates the home directory for new user under /home.
  • Asks for the password.
  • Asks for additional information such as Full Name, Room number, Work phone, Home phone and other information.

Note that you need superuser permissions to execute the command.

adduser command

useradd command

The useradd command does the same thing as adduser command i.e creating a new user but with few differences.

  • It does not create a home directory for the new user by default.
  • It does not ask for password.
  • It does not ask for any additional information.

Note that you need superuser permissions to execute the command.

useradd

Although it does not ask for any additional information by default, you can provide them that information using the flags given below:

-c, --command : GECOS field for the new account.
-D, --defaults : Create new user with default set values.
-m, --create-home : Create user's home directory
-p, --password : Set Password for the account.
-e, --expire : Set the expiry date for the user.

You can view additional flags by using the command:

useradd --help

Which one should I use and when?

Well, in most of the cases you must use adduser command. It's easy to set up password, create home directory etc., using this command.

But that doesn't mean useradd command is useless. If you temporarily want to create a user without providing much details for the account, you can use the useradd command. Generally it's used while executing commands in automated way in scripts.

That's all for the blog. Comment down below your go-to command for creating a user.

Thank you for reading!


Original Link: https://dev.to/kcdchennai/useradd-vs-adduser-which-command-to-use-3mb4

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To