There are several ways to add users to a group in Linux.
The following uses the sudo
group as illustration.
-
gpasswd
,usermod
andadduser
can all be used to add a user to a given group. However, it is suggested that you usegpasswd
as it is more portable and intuitive.gpasswd -a user_name sudo newgrp sudo usermod -aG sudo user_name newgrp sudo # works on Ubuntu but not CentOS adduser user_name sudo newgrp sudo
Just adding an user to a group might not make it work right away. The command
newgrp sudo
make the groupsudo
in effect right away. Of course, you can log out and then log in to make it work. -
Some desktop environment (e.g., GNome, Cinnamon, KDE, etc.) can also do this for you. Taking Cinnamon as an example, you can follow the steps below to add/remove groups for a user.
-
Open
System Settings
. -
Click
Users and Groups
. -
Select the user you want modify.
-
Click on
Groups
. -
Check/uncheck groups from the prompt list.
-
Click the OK to save the changes.
-