Linux File Permission: What are UID vs GID?
Quick Answer: UID is the unique identifier for a file's owner, and GID is the identifier for the group associated with that file, both of which determine access permissions in Linux.
The UID (user identifier) and GID (group identifier) are fundamental concepts for Linux system administration. With that being said, it is critical to understand them before achieving a Linux certification. Understanding how UID and GID affect file permissions and how programs run can make you a better exam taker, administrator, or security pro.
Here, we'll take a quick look at the UID and GID, how to display them, and how they can help you better understand Linux file permissions.
What are UID and GID?
As you might expect, UID is a number associated with a user account, and GID is a number associated with a group.
The root user and group are usually given UID and GID 0. The IDs from 1-99 are also reserved for use by other system accounts. What happens after ID 99 tends to vary by operating system.
For example, some flavors of *nix reserve 100-499 for dynamic system allocation (e.g., if a package you install needs a UID/GID) and begin allocating standard user accounts UID and GID numbers at 500. Other systems reserve 100-999 for dynamic system allocation and start standard user accounts from 1,000 and up.
UID and GID matter for more than just identifying users and groups. When a process is started, or a command is run, the UID or GID that called it dictates privileges and file system access. For example, UID and GID values help your Linux systems differentiate between a root and a user with lower privileges.
How to Display a UID and GID
There are several ways to view a UID and GID. One of the simplest is to look at the /etc/passwd file, which is available on most Linux operating systems. In the /etc/passwd file, the UID is the third field, and the GID is the fourth.
For example, on our Ubuntu 20.04 system where "cooluser" was the first account created, we can see that cooluser's UID and GID are 1000.
cooluser@LAPTOP-5V55HON5:~$ cat /etc/passwd | grep cooluser
cooluser:x:1000:1000:,,,:/home/cooluser:/bin/bash
cooluser@LAPTOP-5V55HON5:~$
You can also find the GID and UID of your current user or other users with the aptly named id command. In the examples below, we use id to check our own UID and GID as well as the UID and GID of "otheruser" with the command id otheruser.
cooluser@LAPTOP-5V55HON5:~$ id
UID=1000(cooluser) GID=1000(cooluser)groups=1000(cooluser),4(adm),20(dialout),24(cdrom),25(floppy),27(sudo),29(audio),30(dip),44(video),46(plugdev),117(netdev)
cooluser@LAPTOP-5V55HON5:~$ id otheruser
UID=1001(otheruser) GID=1001(otheruser) groups=1001(otheruser)
cooluser@LAPTOP-5V55HON5:~$
You'll notice that there are multiple groups in the id cooluser command. This is because the id command prints the real UID/GID, the effective UID/GID is usually the same as the real UID/GID, but not always, and supplementary group IDs. These values come into play once you dive into file permissions and concepts like setUID.
Learn More: Linux Courses
Linux is the third most popular operating system and serves as the backbone of the modern IT industry. This open-source OS powers everything from web servers to cloud platforms and embedded systems. Mastering Linux can enhance your technical skill set and open up career opportunities in system administration, development, cybersecurity, and DevOps.
So, where do you start? Here are our favorite Linux training online courses to help you take your career to the next level:
Final Thoughts: What's Next?
We hope this crash course was helpful! Understanding GID and UID is important foundational knowledge for Linux professionals.
From here, you can dive further into Linux file system permissions or user administration. If you're still not sure where to start but know you want to improve your *nix skills, check out Shawn Powers' Linux Essentials training. Whichever path you take, the important thing is to keep stacking your skills.
Not a CBT Nuggets subscriber? Claim your free week of training.
delivered to your inbox.
By submitting this form you agree to receive marketing emails from CBT Nuggets and that you have read, understood and are able to consent to our privacy policy.