FUNDAMENTALS A Complete Guide for Beginners
Group Identifier or gid in Linux is a term often used to identify groups and their permissions. The gid indicates the group number inside a Linux system. This group system often provides or limits system resources and permission. In this article, I will discuss all the features and aspects of the gid in Linux.
What is gid in Linux?
The gid, short of group identifier in Linux is a collection of users who can share certain permissions and access rights to the system resources. It helps to identify the system and limit what that group can access. There is a numbering system that allows finding information about a group easily. Each group has a unique GID. Such as,
- gid 0 (zero) means root group. This number is reserved for the root in the Linux.
- gid 1-99 are allocated for the system and application.
- gid 100+ (more than 100) is for the user’s group. The users in the system create these groups.
How to Create a Group?
You can create groups in different ways. Sometimes you may want to create groups by serial number. But you may also want to keep gid according to your need. Here are 2 different methods of creating groups:
Method 1: Creating Groups by the Default Serial Number
Creating a group is very easy. But you will find your gid in serial. You can access the gid about the groups from the end of the /etc/group file. Here, as you can see, I created a group called LinuxSimply and by default, the gid is 1004 by serial. See the process below:
sudo groupadd LinuxSimply
cat /etc/group | tail -5
You’ll have to enter your password. In the command line, you’ll find the group name and gid.
Method 2: Creating Groups by gid in Linux
But to create a group with a specific gid, you need to use the -g option. For that execute the following commands:
sudo groupadd -g 3333 LS
cat /etc/group | tail -5
As you can see, at the end of the group file, there are all the groups.
Displaying Group Names and gid in Linux
Using different methods, you can display the groups’ names in the command line. Here are 4 different methods to view groups and gid according to need:
Method 1: Showing the gid of the User’s Group
You can show the gid of the current user’s group using any of the commands below:
id
Or,
id -g USER
In the command line, you will see the gids of the User group.
Method 2: Finding All the Groups with gid Available to the User
You may want to find all the groups gid available to the user using the -G option. It will only show the gid, not the groups name. To find the groups’ names, you need to access the /etc/group file. Run the following command:
id -G softeko
You will find all the gids available to the user in the command line.
Method 3: Finding All the Groups with gid
You can also show all the groups with their gid available in the Linux system. To do that you need to access the group file in the etc folder. But the group file also contains all the names of the system groups. So the whole command line will get filled up. So piping the tail command or less command is recommended, like the below command:
cat /etc/group | tail -5
Or,
cat /etc/group | less
As you can see, the command line the last created groups are shown with their gids.
Method 4: Finding all the Group Names with gid of a User
Sometimes, you know a user name but don’t know about the group names and gids available to the user. You can find it by piping the group file with the grep command:
cat /etc/group | grep softeko
Here, you will see the grep command finding the line with softeko and showing the gid.
Conclusion
Here, you’ve learned about some of the uses of gid and how to find them using the command line. These commands will come in handy when you start using multiple groups and permissions. For professionals and server users, these commands will be a daily driver to find and look at the gids of different groups.
People Also Ask
What is the default GID in Linux?
By default, Linux systems assign UIDs and GIDs to newly created user accounts in a sequential numerical order, beginning at 1000. In practical terms, when you create a new user account during installation, it will be assigned UID 1000 and GID 1000.
How do I see my own groups in Linux?
In Linux, to see the groups you are a member of, you can use the ‘groups’ command followed by your username. For example, groups your_username
.
How to display group ID in Linux?
To display the Group ID (GID) of a specific group, you can use the ‘getent’ command or check the ‘/etc/group’ file. For example, to get the GID of a group called ‘test’, either type getent group test
or grep "test" /etc/group
.
How to remove GID in Linux?
To remove a GID or simply a group in Linux, use the groupdel
command. For example, to remove a group named test use the command, sudo groupdel test
. Note that, you need superuser privileges (sudo) to delete a group.
Similar Readings