what is UID and GID in Linux?

In order to log into a Linux computer you would require a user account. Once you log in to the computer you can access the files and folders available in the computer. In a Linux  system, each user is identified by the kernel with a number called User Identifier or UID. During user creation the system generates a UID and maps it with a username. The /etc/passwd file contains UID to username mapping of all users in the system. In most Linux operating system the value  of UID lies between 0 - 499 for system generated users and  500 - 60000 for new users created. The default UID of root user is 0.


In a multi-user system users with similar characteristics can be added together to create a group. There can be multiple groups and each group is identified by the kernel with a numeral called Group Identifier or GID.  A user can be member of  single or multiple groups.  So a user will have a primary group and one or more secondary groups. Most of the time the primary group will have the same name as username and gid same as that of uid. Such a group is called Personal Primary Group and will contain only one member. /etc/group file contains GID to name mapping of all groups in the system.

To find the UID and GID of a user we use the id command. id command prints the real user ID, real group ID and effective  user ID for a given user. The syntax of id command is as follows

id [option] username
Simply typing id will give the output for the current user whereas id command followed by a username will show the output for the particular user
In the above example id command is used without any argument. This will print the uid (504) and gid (504) of the user calypso. The final field shows the groups of which user calypso is a member. In this case user calypso is a member of the group calypso, which is also the primary group of the user.

Now lets see the user information of root user.






The output displays the uid (0) of user root and gid (0) of the primary group root. The third field shows all the groups of which user root is a member and their corresponding gid. Here the group named root (gid=0)is the personal primary group of the root user and the rest are the secondary groups of the root user.


Comments

Post a Comment

Popular posts from this blog

Understanding awk command with examples

Understanding sed command with example -Part 1

How to install a Software in Linux