One of the most common tasks that we have to face in our Linux operating system is user management and on this occasion, I will focus on indicating
how to add and remove users on Linux using the terminal
.
All the commands and indications included in this tutorial have been tested in Ubuntu 14.04 and CentOS 7. If you remember the tutorial about the
initial configuration of a VPS server
, there we already gave some small instructions to add a user with sudo permissions.
How to add and remove users on Linux
Before I start talking about the commands to add users in Linux, I want to clarify that we have two applications to add new users, which can cause some confusion. The applications are
useradd
and
adduser
, both serve the same, but perhaps
adduser
is a bit more user friendly.
Differences between useradd and adduser
:
-
useradd
: is the binary compiled by the operating system.
-
adduser
: is a script in Perl that performs the same functions as useradd but more friendly than this one. From Ubuntu's own help pages they recommend using adduser.
Arrived here, surely you have a mess in the head for the similarity of both commands, but we solve it in a simple way,
we will pay attention to the help of Ubuntu and we will always use adduser
.
To execute the following commands we will need to have a session open in the terminal with root permissions.
To add a user in Linux we execute the command:
adduser TechnoWikis
In this example the new user will be called
TechnoWikis
, you will use the name you need.
To delete a user we have two commands available again, just as it happened to add a user. These two commands are
userdel
and
deluser
, but we will always use
deluser
for the recommendation of the Ubuntu help (in CentOS there is only the userdel command so we will also explain its operation).
To delete a user in Linux we execute the command:
deluser TechnoWikis
The above command only deletes the user, but does not delete any of its files
, which are usually found in the
/home/nombre
folder. To delete the user and his files, the command to execute is:
deluser --remove-home TechnoWikis
As
in CentOS the deluser command is
not
available
we have no choice but to use the command:
userdel TechnoWikis
If we also want to eliminate the user, delete their files, we will have to use the command:
userdel -r TechnoWikis
As you can see, these are simple steps that anyone can do. I hope the tutorial has helped you.