Linux user management through command line and GUI
Himanshuz.chd 270004408M Comment (1) Visits (39805)
In one of the earlier articles at this blog (here), we learned the Linux user login management. The article explained how user login and password are managed in Linux. Continuing on the same lines. In this article, we will learn how users are managed in Linux. This article will try to cover basics of Linux user management through command line tools as well as through GUI.
Note that since I work on Linux Mint so the GUI part would be applicable only to the Linux debain distributions.
Command Line tools for Linux user / group management
Following are the Linux command line tools for managing users and groups :
Lets understand these tools one by one with the help of some examples.
1. useradd command line tool is used for creating a new Linux user.
The syntax for this command line tool is :
useradd [options] LOGIN
Here is an examples of this tool :
$ sudo useradd --create-home -d /home/nixUser nixUser
The command above will create a user nixUser with its home directory as /home/nixUser. The flag --create-home makes sure that the home directory is created if it does not exist. The creation of this user can be confirmed by examining the /ect/passwd file which should now have an entry for this user.
$ cat /etc/passwd | grep nixUser nixU
So we see that indeed there is an entry for this user in /etc/passwd file.
NOTE: To know more about this file, read our article here.
Now lets set a password for this user. The 'passwd' command would be helpful in this case :
$ sudo passwd nixUser Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
So this way the password for the newly created user can be set.
2. usermod command line tool is used for modifying an existing user account.
The syntax for this tool is:
usermod [options] LOGIN
Here is an example of this tool :
$ sudo usermod -m -d /home/nixUser1 nixUser
The above command sets the new home directory of the user nixUser as /home/nixUser1.
Lets confirm it :
$ ls /home/ admin nixUser1 users
So we see that the new directory was created which replaced the old /home/nixUser home directory.
Here is another example :
$ sudo usermod -c "GuestUser" nixUserThe command above will add the full name for the user 'nixuser' as 'GuestUser'.
This can be confirmed through the following command :
$ cat /etc/passwd | grep nixUser nixUSo we see that the full name was added for the user.
3. userdel command line tool is used to delete a user.
The syntax for this tool is :
userdel [options] LOGINHere is an example of this tool :
The above command would delete the user 'nixUser'.
But if the home directory along with its contents needs to be deleted then use the following command :
$ sudo userdel -r nixUserLets check the home directory :
$ ls /home/ admin users
So we see that the home directory /home/nixUser1 was also deleted.
Please check the man pages of all these three user management commands for exhaustive list of command line options.
Linux (debian) GUI tool for user managementTo start user management through GUI, run the following command :
This will open up following GUI :
Now, click on the Add button. You will be prompted for admin password if you are not root.
Otherwise you will see the following screen :
Here enter the new user name like 'nixuser' and press ok.
The next screen will prompt you to add password for this user.
Fill in the new password and its confirmation box and you will see that new user is created.
You can click the 'Advance Settings' button and do some other settings related to this user.
Finally pressing the 'Delete' button will prompt you for confirmation if you want to delete the user and related directories
One you conform that you want to delete, the user and related directories will be deleted
So In this way users can be managed in Linux both from command line as well from GUI.