This article describes the steps to get a user ID or UID in Ubuntu Linux.
Every user on a Ubuntu Linux system is assigned a unique user ID or UID. A UID is a numeric value defined by the system to identify users.
No two users will share the same UID on Ubuntu Linux. UID can be a handy way to manage and track users on a Ubuntu Linux system with multiple users.
Each user can get their UID simply by running the command id. That is the simplest way to view one’s UID on Ubuntu Linux.
However, there are multiple ways to get UIDs for all users, and the steps below show you how.
Get UID for Users on Ubuntu Linux
As described above, A UID is a numeric value the system defines to identify users. UID can come in handy when managing and tracking users on Ubuntu Linux.
To get your user ID, run the id command shown below.
id
The command above should output a line similar to the one below.
uid=1000(richard) gid=1000(richard) groups=1000(richard),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),122(lpadmin),134(lxd),135(sambashare)
Use the lslogins command to find the User ID
The lslogins command helps you find multiple users’ user IDs or UIDs. When you use the lslogins command with the -u option, it lists all users’ IDs on the system.
Run the lslogins command below to list all UIDs on the system.
lslogins -u
The command above should display lines similar to those below.
UID USER PROC PWD-LOCK PWD-DENY LAST-LOGIN GECOS 0 root 205 0 1 root 1000 richard 80 09:41 Richard
Get User IDs using the getent command
Another tool or utility to display a user ID or UID is the getent command. Use the command format below to see a user ID or UID.
getent passwd <username>
The command display UID for users by reading the contents of /etc/passwd.
For example, If you want to know the UID of the user named geekrewind, you will run the command below.
getent passwd geekrewind
The command should output a single line containing the UID for the users. The third column is the UID of the user.
richard:x:1000:1000:Richard,,,:/home/richard:/bin/bash
There could be other ways to get a user ID or UID that are not listed above. However, the steps above should be a good starting point.
Conclusion:
- Understanding the concept of User ID or UID and its importance in Ubuntu Linux
- Learning multiple methods to retrieve User IDs for individual users and all users on the system
- Exploring commands like id, lslogins, and getent to obtain user IDs efficiently
- Enhancing user management and tracking capabilities on Ubuntu Linux through UID retrieval
- Encouraging further exploration and utilization of additional methods for obtaining user IDs or UIDs in Ubuntu Linux
Leave a Reply Cancel reply