How to Add Users to Groups in Ubuntu Linux

Richard
Written by
Richard
Jan 2, 2023 Updated Mar 19, 2026 2 min read
How to Install VMware Workstation Player on Ubuntu Linux

You add users to groups in Ubuntu Linux to manage permissions by using the `usermod` command in the terminal.

Groups in Ubuntu act as containers that organize users and grant them specific access rights to files and other system resources. When users share group membership, they can collaborate on and manage shared data.

Every user typically has a primary group, often matching their username, and can be added to numerous secondary groups for expanded privileges. For example, to add a user named ‘alex’ to the ‘sudo’ group, you would execute the command `sudo usermod -aG sudo alex`.

⚡ Quick Answer

Use the `usermod -aG groupname username` command in the terminal. This appends the specified user to the existing group without removing them from other groups. For example, `sudo usermod -aG developers jane` adds the user ‘jane’ to the ‘developers’ group.

Add a user to a group in Ubuntu Linux

Now that you know how to add a user to an existing group, let’s consider creating new groups. For instance, you can create a group to restrict users’ resource access. If you add a user to the docker group, they will inherit the group’s access rights and be able to run docker commands.

Here’s the format for adding a user to a group in Ubuntu Linux.

🐧Bash / Shell
sudo usermod -a -G groupname username

Add a user to multiple groups.

🐧Bash / Shell
sudo usermod -a -G group1,group2 username

The commands we’ve covered so far assume the groups already exist.

For example, to add the user geekrewind to the sudo group, you’d run this command:

🐧Bash / Shell
sudo usermod -a -G sudo geekrewind

When adding a user to a new group, you use the -a (append) command. If the group doesn’t exist, the command will return an error.

Change a user’s primary group in Ubuntu Linux

Think about resources users create in Ubuntu. By default, these resources will inherit the rights and access of the user’s primary group, giving them broad access.

In Ubuntu Linux, you can change a user’s primary group. To change a user’s primary group, you’ll use the usermod command with the -g option.

🐧Bash / Shell
sudo usermod -g groupname username

For example, you use the commands below to change the primary group of the user geekrewind to developers.

🐧Bash / Shell
sudo usermod -g developers geekrewind

You can also define a user’s primary and secondary groups when you create their account. For example, here’s how you’d create a new geekrewind account, setting its primary group to users and its secondary groups to wheel and developers:

🐧Bash / Shell
sudo useradd -g users -G wheel,developers geekrewind

To list all groups in Ubuntu Linux, read the post below.

How to list groups in Ubuntu Linux

That should do it!

Conclusion:

  • Adding users to groups in Ubuntu Linux is essential for organizing and administering user accounts.
  • Administrators can effectively manage resource access and permissions by understanding the distinction between primary and secondary groups.
  • The steps outlined provide clear guidance on adding users to single and multiple groups and changing a user’s primary group.
  • Readers can refer to the provided link for instructions on listing all groups in Ubuntu Linux, enhancing their understanding of user and group management.

Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

No comments yet — be the first to share your thoughts!

Leave a Comment

Your email address will not be published. Required fields are marked *

Exit mobile version