Hi, this is Sandra Henry-Stocker, author of the “Unix as a Second Language” blog on NetworkWorld.
In today’s 2-minute Linux tip, we’re going to look at the adduser and deluser commands.
As the names suggest, they are used to add and delete user accounts on Linux systems. But for these commands, you need to use your superuser powers, so we preface them with “sudo”.
To add a new user, you’d use a command like this:
$ sudo adduser dory
With no additional arguments, this command sets up the new user’s home directory, populates it with some start-up files (from /etc/skel), prompts you to set the user’s initial password, and add lines to the /etc/passwd and /etc/shadow files that make it possible for the user to log in.
Unless you specify otherwise, the user will be assigned the next available user ID, be put in his or her own group, and will be assigned the bash shell. You can change these and other settings by adding command options such as these:
--home to put the home director somewhere other than /home
--shell to specify some other shell
--no-create-home to skip creating a home directory
--ingroup to specify an existing group to assign the user to
For example, we could put the new user “sushi” in the shared “fish” group with a command like this:
$ sudo adduser --ingroup fish dory
We have to –
set the initial password – twice
add a brief description for the user
confirm that what we’ve entered is correct
The deluser command does the opposite except that, without additional options, the command removes the account, but not the home directory. If you want to remove the home directory and its contents as well, add the --remove-home option.
$ sudo deluser dory --remove-home
$ ls /home
The account and home directory are now gone.
That’s your 2-minute Linux tip for today. If you liked this video, please hit the like and share buttons. For more Linux tips, be sure to follow us on Facebook, YouTube and NetworkWorld.com.