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 thecat
command to print the contents of the file. Some experienced users may use theecho
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 theecho
command, we can accomplish the job quickly.
In this blog, we are going to discuss about one such function ofcreating a new userusing two commandsadduser
anduseradd
. We'll also talk about which command you must use and when.
Let's dive right into it.
Theaddusercommandcreates a new useron a linux system. Apart from this it does the following things:
Note that you need
superuser
permissions to execute the command.
Theuseradd
command does the same thing asadduser
command i.ecreating a new userbut with few differences.
Note that you need
superuser
permissions to execute the command.
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
Well, in most of the cases you must useadduser
command. It's easy to set up password, create home directory etc., using this command.
But that doesn't meanuseradd
command is useless. If you temporarily want to create a user without providing much details for the account, you can use theuseradd
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!