🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

groupadd Command

Intermediate User Management man(1)

Create a new group

👁 9 views 📅 Updated: Mar 15, 2026
SYNTAX
groupadd [OPTION]... GROUPNAME

What Does groupadd Do?

groupadd creates a new group on the system. Groups are fundamental to Linux permissions, allowing multiple users to share access to files and resources.

groupadd requires root privileges. It creates an entry in /etc/group with an automatically assigned GID (or a specified one). After creating a group, add users with usermod -aG or adduser.

Groups are used for file permissions (rwxrwxrwx), service access (docker, sudo, www-data), and project-based collaboration.

Options & Flags

OptionDescriptionExample
-g Specify GID (group ID) sudo groupadd -g 1500 developers
-r Create system group (low GID) sudo groupadd -r appgroup
-f Exit with success if group exists sudo groupadd -f developers

Practical Examples

#1 Create a group

Creates a new group with an auto-assigned GID.
$ sudo groupadd developers

#2 Create with specific GID

Creates the group with GID 1500.
$ sudo groupadd -g 1500 developers

#3 Create system group

Creates a system group with a low GID (for services).
$ sudo groupadd -r myapp

#4 Add users to new group

Creates a group and adds two users to it.
$ sudo groupadd project-x && sudo usermod -aG project-x alice && sudo usermod -aG project-x bob

#5 Set directory group

Creates group, assigns it to directory, and sets setgid.
$ sudo groupadd webteam && sudo chgrp webteam /var/www/project && sudo chmod g+ws /var/www/project

Tips & Best Practices

Use setgid for shared directories: After creating a group and assigning it to a directory, set the setgid bit: chmod g+s dir/. New files inherit the group.
System vs regular groups: System groups (-r) get low GIDs and are for services. Regular groups get higher GIDs and are for users.
Group changes need re-login: After adding a user to a group, they must log out and back in. Or use newgrp groupname for the current session.

Frequently Asked Questions

How do I create a new group?
sudo groupadd groupname. Then add users: sudo usermod -aG groupname username.
How do I create a shared project group?
sudo groupadd project && sudo usermod -aG project user1 && sudo usermod -aG project user2. Then chgrp -R project /path/to/shared/.
How do I delete a group?
sudo groupdel groupname. This only works if no user has it as their primary group.

Master Linux with Professional eBooks

Curated IT eBooks covering Linux, DevOps, Cloud, and more

Browse Books →