Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

groupadd command in Linux with examples

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Groups in Linux refer to the user groups. In Linux, there can be many users of a single system, (normal user can take uid from 1000 to 60000, and one root user (uid 0) and 999 system users (uid 1 to 999)). In a scenario where there are many users, there might be some privileges that some users have and some don’t, and it becomes difficult to manage all the permissions at the individual user level. So using groups, we can group together a number of users, and set privileges and permissions for the entire group. groupadd command is used to create a new user group. 

Syntax: 
 

groupadd [option] group_name 

Example: 
 

sudo groupadd developers 

Note: 

 

  • Every new group created is registered in the file “/etc/group“. To verify that the group has been created, enter the command 

     

sudo tail /etc/group
  • Output: 

     

  • The file shows group information in the following format: 

     

group_name : password : group-id : list-of-members

Options: 

 

  • -f, –force : This option forces the command to silently abort if the group with given already exists. If this option is used with the -g or –gid option and the group id given already exists, the command forcefully ignores the given group id and creates a new and unique group id. 

     

  • -g, –gid GID : This option is used to provide a group id (numeric) to the new group, and it should be non-negative and unique unless explicitly created to be non-unique (using -o option). If this option is not used, the default id is assigned, which is greater than every other group already present.
  • -h, –help : Display help message and exit.
  • -K, –key KEY=VALUE : Overrides /etc/login.defs defaults (GID_MIN, GID_MAX and others). Multiple -K options can be specified. GID_MIN and GID_MAX are the parameters set in /etc/login.defs which defines the minimum and maximum values that a group id can take. 

    Example: 

     

 groupadd -K GID_MIN=500 -K GID_MAX=700
  •  

  • -o, –non-unique : This option permits to add a group with a non-unique GID.
  • -p, –password PASSWORD : The encrypted password, as returned by crypt(3). The default is to disable the password. This password is visible to the users. You should make sure the password respects the system’s password policy. The group passwords are stored in “/etc/gshadow” file.
  • -r, –system : Create a system group. The numeric identifiers of new system groups are chosen in the SYS_GID_MIN-SYS_GID_MAX range, defined in login.defs, instead of GID_MIN and GID_MAX.
  • -R, –root CHROOT_DIR : Apply changes in the CHROOT_DIR directory and use the configuration files from the CHROOT_DIR directory.

Important Points: 
 

  • To add a new user into the group, the group is mentioned using -g option in the command useradd

     

sudo useradd -g developers new_user 
  • To add an existing user to a group, use the usermod command 

     

usermod -g developers existing_user 
  •  

 

My Personal Notes arrow_drop_up
Last Updated : 28 Feb, 2022
Like Article
Save Article
Similar Reads
Related Tutorials