Skip to content
Ubuntu Linux

How to Retrieve User IDs in Ubuntu Linux

Richard
Written by
Richard
Updated 4 min read
How to Use Sticky Notes in Windows 11
How to Use Sticky Notes in Windows 11
Before you start
  • 6 steps
  • Needs administrator rights

A User ID (UID) is a unique number that Ubuntu assigns to every account. The system uses it, not the username, to decide who owns a file and who can run a program. You can find these numbers in a few seconds from the Terminal app. Press Ctrl+Alt+T to open it.

Run the id -u command to check your own UID. Type getent passwd to see the UIDs for every account on the system. Neither command needs administrator rights.

⚡ Quick Answer

You can find your user ID by opening the terminal and typing `id`. To see all user IDs, use `lslogins -u` or `getent passwd `.

Advertisement

Get UID for Users on Ubuntu Linux

Ubuntu Linux assigns a User ID (UID) to keep track of each account. On a default install, root always has UID 0. The first regular user you create usually gets UID 1000, and the next ones count up from there. Accounts created by services and system packages normally have lower numbers.

The id command shows the UID of the account you are logged in as. Use it when you need to confirm which account you are working in.

Advertisement
  1. Open a Terminal window.
  2. Type the command shown below and press Enter.
💻Code
id

The Terminal prints a single line that looks like this:

💻Code
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)

The number after uid= is your User ID, and the name in brackets next to it is your username. The same line also lists your primary group ID (gid) and the groups you belong to. Don’t mix up the UID and the gid. They often match on a desktop install, but they are two separate values.

Use the lslogins command to find the User ID

The lslogins command shows the user ID for every account on your system at once. It prints a list that pairs each username with its numeric identifier, so you can compare several accounts quickly. It is part of the standard util-linux package, so it should already be installed on Ubuntu.

  1. In the Terminal, type the command shown below and press Enter.
  2. Read the list that appears. If it runs past the top of the window, scroll up with the mouse wheel or Shift+Page Up.
💻Code
lslogins -u

The Terminal prints one line per account, in this format:

💻Code
UID  USER     PROC PWD-LOCK PWD-DENY LAST-LOGIN GECOS
0    root     205        0        1             root
1000 richard  80                    09:41       Richard

The UID is in the first column and the username is in the second. The list includes root and the system accounts, not only people. Regular users are normally the ones with numbers of 1000 and above.

Get User IDs using the getent command

The getent command finds the user ID for one specific account. It reads the same account records as the /etc/passwd file, so it is the quickest way to look up a single user without listing everyone. It can also find accounts that come from other sources the system is set up to use, such as a directory service. A plain look at the file would miss those.

💻Code
getent passwd <username>

This command queries information stored in /etc/passwd.

To look up the UID for an account named geekrewind, follow these steps:

  1. Open a Terminal window.
  2. Type the command shown below. Replace geekrewind with the username you want to check, then press Enter.
💻Code
getent passwd geekrewind

One line comes back with the user’s details, separated by colons. The fields are the username, a password placeholder, the UID, the group ID, the full name or comment, the home directory and the login shell. The third field is the UID.

If you type a username that doesn’t exist, the command prints nothing at all. If that happens, check the spelling of the name.

💻Code
richard:x:1000:1000:Richard,,,:/home/richard:/bin/bash

Other ways to read UIDs exist, but these three commands cover most day-to-day administration. Use id for yourself, lslogins for the full list and getent for one named account.

Knowing how to read User IDs in Ubuntu helps you manage access and file permissions. It also makes it easier to match an account to the numbers you see in file ownership and system logs.

  • 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

Have a question about this guide?

Answered by AI from this guide. Good questions may be added to this page — please don't include personal details.

Did this guide fix your problem?

Richard

About the Author

Richard

Tech Writer, IT Professional

Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.

Advertisement

No comments yet — be the first to share your thoughts!

Leave a Comment

Your email address will not be published. Required fields are marked *