Skip to content

Latest commit

 

History

History
130 lines (109 loc) · 4.25 KB

groupadd-and-groupdel.md

File metadata and controls

130 lines (109 loc) · 4.25 KB

GROUPADD AND GROUPDEL COMMAND

Group Addition (groupadd)

The groupadd command in Linux is used to create a new group in the system. It allows system administrators to define user groups that can be assigned to files or directories for easier management of access control.

Basic Syntax

sudo groupadd [options] groupname

Requires sudo or root privileges. Replace [options] with the appropriate flags to modify group attributes.


Useful groupadd Switches

1. Create a New Group

What it does: Creates a new group with the specified group name.
Syntax:

groupadd groupname

Example:

groupadd developers

Creates a new group called developers.

2. Set Group ID (-g, --gid)

What it does: Specifies a custom Group ID (GID) for the new group. By default, the system will automatically assign the next available GID.
Syntax:

groupadd -g GID groupname

Example:

groupadd -g 1001 developers

Creates a new group called developers with GID 1001.

3. Force Command Execution (-f, --force)

What it does: If the group already exists, this option prevents an error and forces the command to exit successfully.
Syntax:

groupadd -f groupname

Example:

groupadd -f developers

If the developers group already exists, the command will succeed without an error.

4. Create System Group (-r, --system)

What it does: Creates a system group. System groups have GID values lower than 1000 (or the value set in /etc/login.defs).
Syntax:

groupadd -r groupname

Example:

groupadd -r sysadmins

Creates a system group called sysadmins.

5. Allow Non-Unique GID (-o, --non-unique)

What it does: Allows creating a group with a duplicate GID. This can be useful if you want multiple groups to have the same GID.
Syntax:

groupadd -o -g GID groupname

Example:

groupadd -o -g 1001 developers

Creates the developers group with GID 1001, even if that GID is already assigned to another group.

6. Set Password (-p, --password)

What it does: Sets the encrypted password for the new group. It allows the creation of a password for a group, but it's rarely used as groups typically don't have passwords.
Syntax:

groupadd -p 'encrypted_password' groupname

Example:

groupadd -p '$1$dr5MGUev$uZ8QHz4ilePmWugMkj7yA.' developers

Sets an encrypted password for the group developers.


Group Deletion (groupdel)

The groupdel command in Linux is used to delete an existing group from the system. It removes the group from the /etc/group and /etc/gshadow files, effectively removing the group from the system.

Basic Syntax

sudo groupdel groupname

Requires sudo or root privileges. Replace [groupname] with the group to be deleted.


Useful groupdel Switches

1. Delete a Group

What it does: Deletes the specified group from the system.
Syntax:

groupdel groupname

Example:

groupdel developers

Deletes the developers group from the system.


Summary Table

Command Description Example
groupadd Create a new group groupadd developers
groupadd -g GID Create a group with a specific GID groupadd -g 1001 developers
groupadd -f Force command execution if group exists groupadd -f developers
groupadd -r Create a system group groupadd -r sysadmins
groupadd -o Allow non-unique GID groupadd -o -g 1001 developers
groupadd -p Set encrypted password groupadd -p '$1$dr5MGUev$uZ8QHz4ilePmWugMkj7yA.' developers
groupdel Delete a group groupdel developers