ПІДТРИМАЙ УКРАЇНУ ПІДТРИМАТИ АРМІЮ
Uk Uk

useradd vs adduser: Which command to use?

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...

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 thecatcommand to print the contents of the file. Some experienced users may use theechocommand 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 theechocommand, we can accomplish the job quickly.

In this blog, we are going to discuss about one such function ofcreating a new userusing two commandsadduseranduseradd. We'll also talk about which command you must use and when.

Let's dive right into it.

adduser command

Theaddusercommandcreates a new useron a linux system. Apart from this it does the following things:

  • Creates anew group.
  • Creates thehome directoryfor new user under /home.
  • Asks for the password.
  • Asks for additional information such asFull Name,Room number,Work phone,Home phoneand other information.

Note that you needsuperuserpermissions to execute the command.

https://res.cloudinary.com/practicaldev/image/fetch/s--piqRxYpz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/coqul2e1wss70qfw3853.png
 

useradd command

Theuseraddcommand does the same thing asaddusercommand i.ecreating a new userbut with few differences.

  • It doesnotcreate a home directory for the new user by default.
  • It doesnotask for password.
  • It doesnotask for any additional information.

Note that you needsuperuserpermissions to execute the command.

https://res.cloudinary.com/practicaldev/image/fetch/s--Wa_14TI4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a49ebhg0sxqjfpaz40js.png
 

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 useaddusercommand. It's easy to set up password, create home directory etc., using this command.

But that doesn't meanuseraddcommand is useless. If you temporarily want to create a user without providing much details for the account, you can use theuseraddcommand. 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!

Ресурс : dev.to

Scroll to Top