How to Add Users to Groups in Ubuntu Linux
Adding users to groups in Ubuntu Linux lets you share file access and permissions across several 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. These steps work the same on Ubuntu Desktop and Ubuntu Server.
Placing an account into the sudo group gives it full administrator privileges, so it 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. You need to be signed in as a user who already has sudo rights, because only an administrator can change group membership.
To add a user to a group in Ubuntu Linux, run sudo usermod -a -G groupname username in the terminal, replacing groupname and username with the exact names on your system. The command adds the account to the group without removing its existing memberships, and it prints nothing on success. The user must log out and back in before the change applies.
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, so they can share file permissions and run restricted commands.
Replace groupname with the group you want and username with the account you are changing. Group and user names are case-sensitive, so type them exactly as they exist on the system. The change is saved as soon as the command finishes. If the user is signed in right now, they must log out and back in before the new group applies to their session.
Here’s the format for adding a user to a group in Ubuntu Linux. If the command runs without printing anything, it worked. usermod stays quiet on success and only prints a message when something is wrong.
sudo usermod -a -G groupname username
You can also add a user to several groups with a single command. List the group names in one go, separated by commas, and do not put spaces between them. A space ends the list, and the tool will read the next word as a username.
sudo usermod -a -G group1,group2 username
The commands covered so far assume the groups already exist. If you name a group that is missing, usermod stops with an error and does not change anything for that group, so create the group first.
Terminal commands handle this group membership update in Ubuntu Linux. For example, running sudo usermod -aG sudo geekrewind adds the user geekrewind to the sudo group. This gives geekrewind the permissions of the sudo group, which lets them run commands with administrator privileges.
After running it, have the user log out and sign back in. Until they do, their current session still uses the old group list, and sudo will not work for them yet.
sudo usermod -a -G sudo geekrewind
Watch out for typos here too. Targeting a group that does not exist makes the tool throw an error. If that happens, check the spelling of the group name and run the command again.
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 any new files and folders the user creates automatically belong to the new group instead of the old one.
By default, Ubuntu gives each new user a primary group with the same name as the account. Change it only when you want that user’s new files to be owned by a shared group. For simply granting access to something, adding a secondary group is the safer choice.
Primary group modifications in Ubuntu Linux rely on the usermod command paired with the -g option. Note that this is a lowercase g, and it takes a single group. It does not accept a comma-separated list like the secondary-group option does.
sudo usermod -g groupname username
For example, the commands below change the primary group of the user geekrewind to developers. The group must already exist.
sudo usermod -g developers geekrewind
You can also set primary and secondary groups at the moment you create an account, which saves a separate usermod step afterwards. Setting up a new geekrewind account with a primary group of users and secondary groups of sudo and developers uses this structure:
sudo useradd -g users -G sudo,developers geekrewind
Instructions for listing all groups in Ubuntu Linux live in the related post below. It is worth checking the group names there before you run any of the commands above.
How to list groups in Ubuntu Linux
Proper group management keeps multi-user systems secure and organized. Give each person only the groups they need, and review memberships now and then, especially for powerful groups like sudo.
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. Always use -a when appending, and have the user log out and back in afterwards.
- Readers can refer to the provided link for instructions on listing all groups in Ubuntu Linux, enhancing their understanding of user and group management.
Have a question about this guide?
Answered by AI from this guide. Good questions may be added to this page — please don't include personal details.
Did this guide fix your problem?
About the Author
Richard
Tech Writer, IT Professional
Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.
No comments yet — be the first to share your thoughts!