Linux administrators often need to manage users and groups in a Linux/Ubuntu System. User management, access control, and Group management are the basic yet the most important need. In this post, we will learn about
- Creation of a User
- List all Users
- Change Password of a User
- Creation of a Group
- List all Groups
- Addition of a User in a Group
- Show Group of a User
- List all Users in a single Group
- Deletion of a User from a Group
- Deletion of a User
- Deletion of a Group
In this post, we will perform each of the above-mentioned tasks through the terminal.
Creation of a User
We can add a user in the Ubuntu Operating System through GUI or from the terminal. We can either use the simple “adduser” command to add a user or the “adduser –system” command to add a system user.
To create a new system user,
To create a simple user,
After running the above command, it will ask you to set the new password for the newly created user twice.
It will then ask you to provide the username, room number, phone number of your work and home, and others. Provide the desired details and hit “Enter”
After providing the details, it will ask you either the provided information is correct or not. Press “y” to continue and press Enter if the information is correct.
List all Users
Now, if you want to list all Ubuntu users in the terminal, you can type the following command.
It will list all the users of the Ubuntu System.
Change Password of a User
If you want to change any user’s password, you first have to log in with that specific username. For example, for changing the password of linuxuser1,
After running the above command, it will ask you to enter the password of that user, type in the password, and hit “Enter”.
You can see that the username is changed.
Now, run the “passwd” command,
Enter your previous password first, and then provide the new password twice and hit Enter. If both of the new passwords will be the same, then the password will be changed successfully.
Creation of a Group
You can create or add a Group in any Linux based operating system using the “addgroup” command.
As you can see that the “linuxgroup1” is created successfully.
List all the groups
Now, If you want to list out all the groups that exist in the Ubuntu Operating system, run the command given below
It will list out all the existing groups of the operating system.
Addition of a User in a Group
The users can be grouped as well in Ubuntu. We can add a user to the group by providing the group name and username to the “usermod” command with the -aG flags like this,
The user “linuxuser1” will be added to the “linuxgroup1” group.
Show Group of a User
To see the user’s group, type the “groups” command in the terminal and hit Enter. It will show the groups of the user. You first have to log in with that specified user and then run the “groups” command.
As you can see that the “linuxgroup1” is listed as the group of “linuxuser1”.
List all the Users in a single Group
To list all the users of any group, run the “cat”, “cut”, and “grep” command with the following parameters.
Make sure to replace the group name with your desired group name. For example, “linuxgroup1”
You can see that the users in “linuxgroup1” are listed.
Deletion of a User from a Group
If you want to remove a user from any group. You can do so by typing the user name and group name followed by the “deluser” command.
You can see that the user is removed from the “linuxgroup1” group.
Deletion of a User
If you want to delete a user from the Operating system. You can simply delete it by running the “deluser” command with the user name
If you want to delete the user’s home directory as well, use the “–remove-home” flag with the “deluser” command like this
And now, if we list the “/home” directory, there will be no more home directory of the “linuxuser1” user.
Deletion of a Group
To remove the group from the operating system, run the “delgroup” command with the group name like this
The group is deleted successfully.
Wrap Up
Managing the users is a very important task that Linux administrators perform. In Linux based distributions, we can easily create new users and manage them. This article describes user management on the Linux based system in detail.