How to Add Users to Groups in Ubuntu Linux
Adding users to groups in Ubuntu Linux lets you share file access and permissions across multiple accounts at once without changing settings for each person individually. A user group is a collection of system accounts that share the same access rights to folders and programs on your machine.
Placing an account into the sudo group grants full administrator privileges so you can run system-wide commands. To add a person named alex to that group, open your terminal (the command-line interface) and run 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
To add a user to a group in Ubuntu Linux, use the terminal command sudo usermod -a -G groupname username. This adds the user account to a secondary group without removing them from their current groups, letting them share file permissions and run restricted commands right away.
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 covered so far assume the groups already exist.
Terminal commands accomplish this group membership update in Ubuntu Linux. For example, executing sudo usermod -aG sudo geekrewind adds the user geekrewind to the sudo group. This grants geekrewind the permissions of the sudo group, allowing them to run commands with administrator privileges.
sudo usermod -a -G sudo geekrewind
Always include the -a flag so the system appends the user to the new group instead of overwriting their existing memberships. Watch out for typos here, because targeting a missing group causes the tool to throw an error.
Change a user's primary group in Ubuntu Linux
To change a user's primary group in Ubuntu Linux, run the terminal command sudo usermod -g groupname username. This updates the main group attached to the user account so that any new files and folders you create automatically belong to the new group instead of the old one.
Primary group modifications in Ubuntu Linux rely on the usermod command paired with the -g option.
sudo usermod -g groupname username
For example, the commands below change the primary group of the user geekrewind to developers.
sudo usermod -g developers geekrewind
Account creation allows defining primary and secondary groups simultaneously. Setting up a new geekrewind account with a primary group of users and secondary groups of wheel and developers uses this structure:
sudo useradd -g users -G wheel,developers geekrewind
Instructions for listing all groups in Ubuntu Linux live in the related post below.
How to list groups in Ubuntu Linux
Proper group management keeps multi-user systems secure and organized.
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, run the usermod command. All groups listed must already exist on the system; users cannot join non-existent groups. The -a option tells usermod to append or 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!