Home Linux How To Add User To a Group in Ubuntu

How To Add User To a Group in Ubuntu

0

Knowing how to manage groups and users is an important skill. This is especially true if you have to create and work with many groups and assign multiple users to the group.

Adding users to groups in Ubuntu and also knowing how to delete users is something you should be able to do effortlessly as a root user. Effective management of users and group is necessary in order not to compromise the security of the system.

Protecting private and sensitive information protection is possible when you give users and groups the appropriate permissions.

This article will explain all you need to know about creating groups, and about how you can add users to groups in Ubuntu. It will explain simple but effective management techniques you can use.

Understanding the Root User

The first thing you need to understand is what the role of the root user is. As the name implies, the root user is at the foundation of all that is done in Ubuntu.

The root user has the authorization to perform various administrative operations. To perform any of the tasks that will be explained in this article, you need to be given root privileges.

Ubuntu is different from most other Linux distributions such as Debian and CentOs, because it does not allow the root user to log in directly. In Ubuntu, a functionality named Sudo is created so you can perform various administrative operations. A password needs to be provided with the Sudo commands. This is to ensure the accountability of the administrator for all operations.

The first user created after the installation of Ubuntu is given the sudo rights. In other words, the first user created is the root user, and has all the accompanying privileges.

That user is added to the list of “sudoers” in /etc/sudoers file. Only an authorized sudoer can perform all the operations that will be discussed in this article.

Managing Users

A user with root privileges or a sudoer may add users to groups in Ubuntu. Apart from being able to add a user, there are other operations that can be performed. These will be explained also. Users can be added to the Ubuntu system through the user interface. Users can also be added through the command line. Furthermore, advanced operations need to be performed through the command line.

Add User To a Group in Ubuntu Through the GUI

As has already been stated, you can add users through the user interface. This is perhaps the most basic of user management operations.

The first step in adding a user through the graphic interface is to open the account settings dialogue. You can do this either through Ubuntu dash or by clicking the down arrow at the top right side of your screen. Click your username and then select account settings.

Add User to Group Ubuntu

A user dialog will open, in it, all the fields will be disabled by default. In order to do any father work with the dialog, you’ll need to provide authentication. Tap the unlock button at the top right corner of the user dialog.

How To Add User To a Group in Ubuntu

In the authentication dialog that opens, provide needed authentication information, so you can proceed as administrator. After providing the password, click authenticate. Only after authentication will all the fields in the users dialog be enabled for you to work on.

How To Add User To a Group in Ubuntu

Click add user and the add user dialog will open for you to enter user information. You can choose to create either a standard or an administrative user. After you have provided the needed information, you will be able to click the Add user button. Click the add button.

Clicking the Add button creates a new user which you will be able to see in the users dialog.

add

Add User To a Group in Ubuntu Through the Command Line

The second way you can add users is through the command line. The command line gives the administrator greater control over user management than using the GUI.

To add a new user, open the terminal either through Ubuntu dash or by pressing Ctrl + Alt + T. With the terminal open, add a new user by entering the command:

$ sudo adduser [username]

Put the username you want to give the new user in the command.

You will have to enter a password for sudo. You will have to enter the password a second time to confirm you entered the right password. You can choose to enter biodata for the new user if you wish.

After looking through the information you provided if the information is correct enter Y and hit the Enter button.

Hitting Enter creates the new user. This seems to be a simple and straightforward way of adding a new user in Ubuntu.

Giving Root Privileges to a User

You can give a user root privileges. This will enable the user to perform various user and group management operations. To give user root privileges, you will have to edit the visudo file that contains the list of sudoers on the system. To open the visudo file, use this command:

$ sudo nano visudo

Entering the command will open the visudo file in the nano editor. To give full root access to a specific user, use the command below:

[username] ALL= (ALL) ALL

To create a group of user you can assign aliases to, use these commands:

User_Alias ADMINS = [username]
Cmnd_Alias HTTPD= /etc/init.d/httpd
ADMINS ALL= HTTPD

Exit the file by pressing Ctrl + X, then enter Y, and hit the Enter button to save the changes you made.

The user will then be granted full root access.

Managing Groups on Ubuntu

Apart from user management, you can manage entire groups on Ubuntu. In a way, it may make your tasks easier and faster. For instance, you can choose to give file access and administrative rights to a whole group instead of each user individually.

Unlike user management—in which some tasks could be performed either through the user interface and command-line— group management can only be done through the command line.

Adding a Group on Ubuntu

You can create a new group easily on Ubuntu. To add a new group, open the terminal, and enter the following command:

$ sudo addgroup [groupname]

You can replace groupname with the name you want to give the group you created. A new group will be created at the end of the process. The group will be given a group  ID (GID).

Adding Users to a Group

After you’ve created a group, you’ll naturally want to add users to the group. Also, if you’ve created a new user, you will want to add the user to a group. Existing users may also be added to existing groups. To add an existing user to a group, use the following command:

$ sudo adduser [username] [groupname]

If you’re adding a user “joe” to group3, the command will be:

$ sudo adduser joe group3

It is also possible to add a user to multiple groups. In the command, separate each group with a comma.

Viewing Group Information

In addition to creating groups and adding users to existing groups, you can view group information.

To view the members of a group use this command:

$ groups username

To view the list of group members along with their GIDs, use:

$ id username

Note that the GID displayed is for the primary group of the member. Users can have multiple groups only one of those groups is a primary group.

How to Change the Primary Group of a User

As has been stated, a user can be in multiple groups. A user has one primary group and can have several secondary groups. The primary group is the group for which the GID is displayed in the output of the id command. To change the primary group if a user use:

$ sudo usermod -g [newPrimaryGroup] [username]

Assigning Group While Creating User

We have already shown how to add a user to a group or several groups. The creation of a new user, and assigning to a group can be done simultaneously. The command to assign a group while creating a user is:

$ sudo useradd -G [groupname] [username]

Set or Change Password for User

While you are creating a new user, you have the option of setting a password for the user. Though you can decide not to, it is advisable for you to set a password. This is for the security of the system, to prevent unauthorized access to private or sensitive information. You assign a password using this command:

$ sudo passwd [username]

You will then be able to enter a new password. You will enter the password twice to ensure it is correct.

Conclusion

Knowing how to manage users and groups in Ubuntu is key for security and efficiency. You can manage users through the user interface and command line. Managing groups is done through the command line. Learning how to add users to a group is a very easy task with this guide.

LEAVE A REPLY

Please enter your comment!
Please enter your name here