sudo usermod -aG groupname username, for example sudo usermod -aG www-data alex. The -a (append) flag keeps the user’s other groups. The change applies the next time the user logs in; check it with id alex. The same command works on Ubuntu, Debian, AlmaLinux and Rocky Linux.
Before you start
- Connect with SSH as root or a sudo user. Root can leave out
sudo. - A group is a named set of users. Files have an owner and a group, and permissions decide what each can do. Putting users in a group is how you let several people share files.
How to add a user to a group
1
Add the user
sudo usermod -aG developers,www-data alex.2
Check the result
3
Log in again
The user must log out and back in (or start a new SSH session) before the new group applies. Running processes keep their old groups.
How to create and delete groups
How to remove a user from a group
How to create users
- Ubuntu / Debian
- AlmaLinux / Rocky
adduser asks for a password and creates /home/alex.useradd options on any distribution:
How to list users and groups
www-data or mysql.
How to change, lock and delete users
passwd -l only blocks password logins. A user with an SSH key can still log in. To stop all logins, expire the account with usermod --expiredate 1 or remove the key from ~/.ssh/authorized_keys.How to check it worked
Start a new SSH session as the user and runid. The new group must appear in the list. To test file access, create a shared folder:
developers can now create files in /srv/shared. The 2 (setgid) makes new files inherit the developers group.
Frequently asked questions
Why doesn’t my new group work yet?
Group membership is read at login. Log out and back in, or runnewgrp developers to start a shell with the new group straight away.
What is the difference between a primary and a secondary group?
The primary group (usually named like the user) is the group new files get. Secondary groups, added withusermod -aG, give extra access. id shows the primary group as gid= and all groups under groups=.
How do I give a user admin (sudo) rights?
Add them tosudo on Ubuntu/Debian or wheel on AlmaLinux/Rocky. See how to create a sudo user.
Can I edit /etc/passwd or /etc/group directly?
You can, but a typo can lock everyone out. Useusermod, gpasswd and groupadd, or sudo vigr and sudo vipw, which lock the file and check it.
Related guides
VPS and dedicated server guides
Every server guide in one place.
Create a sudo user
Give a user admin rights.
File permissions explained
chmod and chown in plain words.
Who is logged in
Check sessions and login history.
Checked against the
usermod, useradd, userdel, gpasswd and passwd man pages from the shadow-utils project on 4 November 2026; commands tested on Ubuntu 24.04 LTS. Commands can differ on other distributions or releases.Need Extra Help?
If you encounter any issues, our support team is ready to assist:- Live Chat: Quick assistance via our website.
- Support Ticket: Open a Ticket
- Discord: Join our Community
- Email: support@freakhosting.com
Last Updated: November 2026