Raspberry Pi

How to Add or Remove a User from a Group in Raspberry Pi

The Raspberry Pi system allows its users to create multiple users and each user has a different group depending upon the privileges and the data they have. If you have created a user on Raspberry Pi other than the default user “pi” and want to assign/unassign the same privileges as the default one, you can add it to the groups, to which the default user belongs to.

In this article, we will guide you on how to add or remove a user from a group in Raspberry Pi.

How to Add or Remove a User from a Group in Raspberry Pi

Before moving towards adding or removing a user from the group, you must first learn how you can create a new user on Raspberry Pi:

Create a New User

To create a new user in Raspberry Pi, use the below-mentioned command:

$ sudo adduser <name-of-user>

Example

Let’s create a new user with the name “linux_hint”. Whenever a new user is created, a new group and a new directory with the same name are also created:

$ sudo adduser linux_hint

After entering the above command, it will ask for a password, you can set any password:

Then retype the password after which it will ask for some basic user information, you can enter the required information or just skip by pressing Enter and in reply to a final prompt press Y for yes:

Once a new user is created on Raspberry Pi successfully, it’s now time to add this user to a group, to which the default user “pi” belongs.

Add a User to a Group

Before, adding a user to a group, you have to check the group to which new user belong using the below-given syntax:

Syntax

$ groups <user_name>

Example

$ groups linux_hint

In the output, it can be seen clearly that the new user is only included in its own group and no other groups.

Now, check the groups to which pi (default user) belongs using the following command:

$ groups pi

In the below-given output, the list of groups will appear in which “pi” is present, the list includes multiple groups such as dialout, cdrom, adm, audio, video, games, and others.

Now if you now want to allow the new user to have access to different groups that were allowed by “pi” user, you can use the below-mentioned command along with the name of the user and group name:

Syntax

$ sudo adduser <user_name> <group>

Example

In the examples below, I am adding my user “linux_hint” to groups of “pi” user:

$ sudo adduser linux_hint <group>

Add the user to groups one by one, you can add a user to as many groups as you want:

Here, I am adding the user “linux_hint” to dialout:

$ sudo adduser linux_hint dialout

Here, I am adding the user “linux_hint” to cdrom.

$ sudo adduser linux_hint cdrom

If you try to add the user to more than two groups at a time then it will show you an error message stating that one name of the group is allowed. So, you have to be patient while adding the user to a group and add user to each group one by one:

Here, I have quickly added the user “linux_hint” to the groups of “pi”.

$ sudo adduser linux_hint video

$ sudo adduser linux_hint plugdev

$ sudo adduser linux_hint games

$ sudo adduser linux_hint users

$ sudo adduser linux_hint input

$ sudo adduser linux_hint render

Adding the created users to sudo users list will allow root privilege to the users, thus they can execute commands with root privileges. You can use the below-given command to add your users to sudo users list.

Here, I have assigned the sudo (root) privileges to the user “linux_hint”.

$ sudo adduser linux_hint sudo

To confirm the user new user is added to all the groups successfully, you can use the below-mentioned command:

$ groups linux_hint

In the below output, it can be seen clearly that the new user “linux_hint” has been added to all desired groups successfully:

Remove a User from a Group

If you want to remove a user from a group, you can use the following syntax with the name of the group you want your user to be removed.

Syntax

$ sudo deluser <user_name> <group>

Example

Here, I am taking away the sudo privileges from the user linux_hint

$ sudo deluser linux_hint dialout

Completely Remove a User from Raspberry Pi

If you want to completely remove a user along with all its group privileges, you can use the below-written command:

Syntax

$ sudo deluser <user name>

Example

$ sudo deluser linux_hint

The above command will remove the user “linux_hint” from Raspberry Pi.

Conclusion

You can use the “adduser” command along with the username and name of a group to add a new user to a group. A user can be added to as many groups as required. If you want to remove a user from a particular group, you can use the “deluser” command along with the name of that group. However, if you are interested in completely removing the user from the system, you can simply use the “deluser” command without any group name.

About the author

Zahra Zamir

An Electronics graduate who loves to learn and share the knowledge, my passion for my field has helped me grasp complex electronics concepts and now I am here to share them with others.