3 basic Linux group management commands every sysadmin should know
source link: https://www.redhat.com/sysadmin/linux-commands-manage-groups
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
3 basic Linux group management commands every sysadmin should know
Posted: October 28, 2021 | by Damon Garn (Red Hat)
Groups make it easy to associate users with similar access-control requirements, so managing users and groups is a key responsibility for sysadmins. As I mentioned in my article on managing users, I like simple commands with a logical syntax. Such commands are easier to remember, particularly for new administrators.
The three commands used to manage group accounts on Red Hat Enterprise Linux (RHEL) and RHEL-like distributions fit this description nicely:
- Add a group:
groupadd
- Modify a group:
groupmod
- Delete a group:
groupdel
As in my overview on user account administration, these concepts apply to any distribution of Linux.
Groups make it easier to associate users that have similar access control requirements. Tyler Carrigan's article Managing local group accounts in Linux covers some of this content.
groupadd
Sysadmins are likely to add groups that represent specific and varied needs to Linux servers. Most of these needs center on controlling access to files, directories, or other resources. You can even use groups help manage sudo
access.
To create a group, use the following command:
$ sudo groupadd projectA
Note: These commands require root or administrative privileges.
This command adds projectA to the /etc/group
file. The file contains the group name, password (if any), group ID, and a list of existing members. The group membership is empty by default. The fields are separated by colons.
There are a few options for groupadd
, but a common one is --gid
(-g
for short), to specify a group ID (GID) number.
[ You might also be interested in the Bash shell scripting cheat sheet. ]
groupmod
Creating a group is only the first step. You might also need to modify the group by using the groupmod
command. The most common group modifications consist of name changes.
Note: Adding or removing a user from a group modifies the user, not the group, by using the usermod
command.
Group modification options include:
--gid
(-g
): Change the GID--new-name
(-n
): Change the group name
Therefore, if you need to update a group name from projectA to projectZ, use:
$ sudo groupmod --new-name projectZ projectA
The projectA string is the command's argument.
After modifying the group, use the tail
or cat
commands to check the /etc/group
file contents to ensure the desired settings are in place.
groupdel
You may need to delete a group. Deleting a group does not delete the user accounts that are members of the group.
To delete the projectA group, type:
$ sudo groupdel projectA
Other than the --help
option for help, the other option sysadmins commonly use is --force
, which forces the group deletion.
Wrap up
The three commands used to manage groups are quite similar to the user management commands. There are few options to remember, yet these six commands to manage users and groups are logical and straightforward.
- Add a group:
groupadd
- Modify a group:
groupmod
- Delete a group:
groupdel
To manage users, use:
- Add a user:
useradd
- Modify a user:
usermod
- Delete a user:
userdel
Because user and group management are such common and important tasks for Linux sysadmins, you would be wise to learn and memorize these commands.
Recommend
-
4
Basic Network Troubleshooting or What Do I Do Before I Call My SysAdmin ? Jun 12, 2002 Basic Network Troubleshooting or What Do I Do Before I Call My SysAdmin ? Last updated: 6/16/2002; 10:22:21 AM...
-
6
Basic Linux Commands for Beginners Knoldus Blog Audio Reading Time: 8 minutes Le...
-
8
3 basic Linux user management commands every sysadmin should know How to use the useradd, usermod, and userdel commands is e...
-
8
Basic UNIX/Linux commands for Interview Questions – Part 1 Some basic UNIX/Linux commands:… from College notes ! Q1. Start UNIX/Linux while logging in remotely to telnet Ans: [st...
-
15
Jdk Posted on Nov 17 ...
-
2
Basic Process Management commands for Linux: Reading Time: 4 minutes In this blog we will get to know about Process Management In Linux: Process management on Linux simply operates i.e...
-
4
4 SSH tricks that every sysadmin should know Learn how to run one-off commands, tunnel other applications, and securely copy...
-
5
Deprecated Linux commands, Podman Compose vs. Docker Compose, and more sysadmin tips Check out Enable Sysadmin's top 10 articles...
-
7
9 basic commands that every new Linux users need to know 180 views 6 months ago Linux Whenever thinking about Linux,...
-
8
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK