How to Add Users to Groups in 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`.
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
You can add an existing user to a new or existing group in Ubuntu Linux using a simple command. This lets you give that user the same permissions as other members of the group, like running Docker commands if you add them to the docker group.
Here’s the format for adding a user to a group in Ubuntu Linux.
sudo usermod -a -G groupname username
Add a user to multiple groups.
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:
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
Changing a user’s primary group in Ubuntu Linux affects the ownership of files and folders they create. By default, new files belong to the user’s primary group, so changing it can alter who has access to those resources.
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.
sudo usermod -g groupname username
For example, you use the commands below to change the primary group of the user geekrewind to developers.
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:
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.
How do I add a user to multiple groups in Ubuntu?
To add a user to multiple groups, you can run the usermod command. All groups listed must already exist on the system. You can't add a user to non-existent groups. The -a option tells usermod to append / add this user to other groups.
Was this guide helpful?
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!