Skip to main content

User Management

Get User ID in Ubuntu

Looking for the UID of a particular user? Here's how to get the user IDs in the Ubuntu command line.

User ID (UID), is nothing but a numeric value defined by your system to identify the users.

And if your system is running with multiple users, UID can be handy when you want to manage them.

The easiest way to get the UID use the id command:

id
use id command to get UID in ubuntu

But that's not it. There are multiple ways of getting the UID of the user so let's have a look at them one by one.

How to find user ID in Ubuntu

You can't expect Linux to have one solution and that goes the same with this case.

So let's get started with the most convenient one.

Use the lslogins utility to find the user ID in Ubuntu

As I mentioned earlier, I find the lslogins utility the best when it comes to finding UID as it does not clutter the terminal window and gets me the relevant information only.

The key advantage of using lslogins is you get the UID of every user just by using the -u option:

lslogins -u
use the lslogins to get user ID in ubuntu

Use the getent utility to find the user ID in Ubuntu

You can get the list of the users by reading the contents of /etc/passwd and the getent utility does exactly that.

To find the UID using the getent command, all you'd need to do is follow the given command syntax:

getent passwd <username>

For example, If I want to know the UID of the user named abhiman, I will be using the following command:

getent passwd abhiman
use getent utility to get the UID of user in ubuntu

Seems confusing right? Here's the explanation:

meaning of /etc/passwd file

Use the id utility to find the user ID in Ubuntu

I've already mentioned this utility at the beginning of this guide where I explained how you can use the id command without any options and it will be the UID of the currently logged-in user:

id
find user ID in ubuntu using the id command

But what if you want to know the UID of the other user? It is quite simple actually.

All you need to do is append the username with the id command and that's it:

id <username>

For example, if I want to know the UID of the user name abhiman, I will be following the given command:

id abhiman
find UID of specific user using the id command in ubuntu

And here you have it!

Wrapping Up

This was a quick tutorial on how you can find the UID in Ubuntu. I personally use the first method (using lslogins) as it beings the UID of every user without any hassle.

And if you have any issues including errors or suggestions, feel free to let me know in the comments.