Groupmod Command in Linux/Unix With Examples | Code Factory

Donate : Link

Medium Blog : Link

Applications : Link

groupmod command in Linux is used to modify or change the existing group on Linux system. It can be handled by superuser or root user. Basically, it modifies a group definition on the system by modifying the right entry in the database of the group.

~# groupmod --help
Usage: groupmod [options] GROUP

  -g, --gid GID                 change the group ID to GID
  -h, --help                    display this help message and exit
  -n, --new-name NEW_GROUP      change the name to NEW_GROUP
  -o, --non-unique              allow to use a duplicate (non-unique) GID
  -p, --password PASSWORD       change the password to this (encrypted) PASSWORD
  -R, --root CHROOT_DIR         directory to chroot into
  -P, --prefix PREFIX_DIR       prefix directory where are located the /etc/* files

Files: The groupmod command has following files.

  • /etc/group: Group Account Information.
  • /etc/gshadow: Secured group account information.
  • /etc/login.def: Shadow passwd suite configuration.
  • /etc/passwd: User account information.

Using groupmod with options:

1. -g, –gid GID

~# tail -1 /etc/group

~# groupmod -g 1002 cf

~# tail -1 /etc/group

2. -n, –new-name NEW_GROUP

~# tail -1 /etc/group

~# groupmod -n CodeFactory cf

~# tail -1 /etc/group

3. -o, –non-unique

~# tail /etc/group

~# groupmod -g 1002 code
groupmod: GID '1002' already exists

~# groupmod -og 1002 code

~# tail /etc/group

4. -p, –password PASSWORD

~# groupmod -p Abc@1 code

~# tail /etc/gshadow

5. -R, –root CHROOT_DIR

~# groupmod -R / code

6. -P, –prefix PREFIX_DIR

~# groupmod -P / code

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s