UID and GID on Linux/ Unix


The user ID (or UID) is a unique number that differentiates a user from any other user. The group ID (GID) determines the primary category of user that the user is. Groups may be things like ‘staff’, ‘student’, ‘engineering’, ‘research’, or any other descriptive term that can be used to partition users in a meaningful way.

/etc/passwd

One of the most critical of all files in Linux is /etc/passwd. All user accounts are stored here, with identifying information like so:

username:password:userID:groupID:realname:homedirectory:shell

For example, a user “mybasicknowledge” who was added as user 300 and group 200 has an entry that might look like this:

mybasicknowledge:x:300:200:Fred Smith:/home/fred:/bin/bash

To find a specific user’s UID, goto the terminal and type the following (replace the username with the actual username) -

id -u username

or

id

To find a user’s GID, at the Unix prompt -
id -g username

If you wish to find out all the groups a user belongs to, type in -

id -G username

If you wish to see the UID and all groups associated with a user, enter id without any options -

id username

Syntax

id [-a] [-G] [-g] [-u] [user]

-a       Reports user name, use ID and all the groups to which the user belongs.
-G      Output all different group IDs (effective, real and supplementary) only, using the format "%u\n". If there is more than one distinct group affiliation, output each such affiliation, using the format " %u", before the new line character is output.
-g       Output only the effective group ID, using the format "%u\n".
-n       Output the name in the format "%s" instead of the numeric ID using the format "%u".
-r       Output the real ID instead of the effective ID.
-u       Output only the effective user ID, using the format "%u\n".
user    The user (login) name for which information is to be written.