: Learn how to add a user to a group in Linux using the usermod
and gpasswd
commands. This guide provides step-by-step instructions to manage user group memberships effectively on any Linux distribution.
1. Open Your Terminal
First, you need to open your Terminal. This is where you’ll run commands to interact with your system. You can open it by searching for “Terminal” in your app menu or by pressing Ctrl + Alt + T
on your keyboard.
2. Use the usermod
Command
To add a user to a group, you’ll use the usermod
command. The general syntax is:
sudo usermod -aG groupname username
sudo
: Runs the command with superuser (administrator) privileges, which you need to modify user settings.usermod
: The command used to modify user accounts.-aG
: The-a
option appends the user to the group (instead of replacing their existing group memberships). The-G
option specifies the group.groupname
: The name of the group you want to add the user to.username
: The name of the user you want to add to the group.
For example, if you want to add a user called john
to a group called developers
, you would run:
sudo usermod -aG developers john
3. Verify the User Was Added to the Group
To confirm that the user was successfully added to the group, you can use the groups
command followed by the username:
groups john
This will list all the groups that the user john
is a member of. If the user was successfully added to the developers
group, it will appear in the list.
4. Log Out and Log Back In
In some cases, the user may need to log out and log back in for the changes to take effect. Alternatively, you can restart the system if needed.