Lecture # 18 - Group Management

Lecture # 18 - Group Management

Group Management in Linux

Creating a new Group:

There are two commands that can add a group.

  • groupadd:

    groupadd is a low level utility. This command is written as sudo groupadd [options] [group-name] .

  • addgroup:

    addgroup is a high level utility. This command is written as sudo addgroup [options] [group-name] .

Deleting a Group:

There are two commands to delete a group.

  • groupdel:

    goupdel is a low level utility. This command is written as sudo groupdel [options] [group-name] .

  • delgroup:

    delgroup is a high level utility. This command is written as sudo delgroup [options] [group-name] .

Change Group ID:

To change the group id sudo groupmod --gid [new-ID] [group-name] is used.

Change Group Name:

To change the group name sudo groupmod --new-name [new-group-name] [old-group-name] is used.

Add User to a Group:

There are two commands to add a user to a group.

  • usermod:

    To add a user to a group using usermod, sudo uermod -aG [group-name] [user-name] is used.

  • gpasswd:

    To add a user to a group using gpasswd, sudo gpasswd -a [user-name] [group-name] is used.

Add User to a Group while Creating a User:

There are two commands for adding a user to a group while creating a user.

  • useradd:

    To add a user to a group while creating a user sudo useradd -G [group-name] [user-name] is used.

  • adduser:

    To add a user to a group using adduser, sudo adduser [user-name] [group-name] is used.

Exit a User from all Groups:

To exit a user from all the groups sudo usermod -G "" [user-name] is used.

Exit from all the Groups and add to a Specified Group:

To exit from all the groups and add to a specified group sudo usermod -G [group-name] [user-name] is used.

Removing a User from a Group:

There are three commands to remove a user from a group.

  • gpasswd:

    To remove a user from a group using gpasswd, sudo gpasswd -d [user-name] [group-name] is used.

  • deluser:

    To remove a user from a group using deluser, sudo deluser [user-name] [group-name] is used.

  • userdel:

    To remove a user from a group using userdel, sudo userdel -G [group-name] [user-name] is used.

Groups joined by the User:

To see the groups joined by the user groups [user-name] is used.

Users in a group:

To see the users in a group getent group [group-name] is used.