DEV Community

Cover image for How to List Users and Groups in Ubuntu Using Command Line
Meghna Meghwani for ServerAvatar

Posted on • Originally published at serveravatar.com

How to List Users and Groups in Ubuntu Using Command Line

If you’ve been working with Ubuntu for any length of time, you’ve likely encountered situations where you need to list users and groups in Ubuntu, check which user accounts exist on the system, or find out which groups a specific user belongs to.

Maybe you’re onboarding a new team member and need to grant them access to a specific directory. Maybe you’re debugging a permission error and can’t understand why a user can’t reach a file they should have access to. Or maybe you’re inheriting a server from someone else and need to audit who’s on it.

That’s exactly what we’re covering today. This guide walks you through everything you need to know about listing users and groups in Ubuntu using the command line. We’ll look at the files that store this information, the commands that query them, and some practical scenarios where this knowledge actually matters.

TL;DR

  • Ubuntu stores user data in /etc/passwd and group data in /etc/group
  • Use getent passwd or cat /etc/passwd to list all users
  • Use getent group or cat /etc/group to list all groups
  • The id command shows a user’s UID, GID, and group memberships in one shot
  • The who and w commands reveal who’s currently logged into your system
  • Group membership determines what files and resources a user can access

Understanding How Ubuntu Tracks Users and Groups

Before we dive into commands, it helps to understand the underlying system. Ubuntu, like most Linux distributions, stores account information in plain-text files that live in the /etc directory.

For additional guidance on managing Ubuntu accounts and permissions, refer to the official Ubuntu user-management documentation.

The three key files are:

  • /etc/passwd : holds user account information
  • /etc/shadow : stores password hashes and password-aging information. It is normally accessible only to the root user or privileged system processes.
  • /etc/group : stores group definitions

You can open and read all three of these files right now. They follow a predictable format, and once you understand that format, you’ll have much more control over how Ubuntu manages access to your system.

How Ubuntu Defines a User Account

Every user on an Ubuntu system has a corresponding line in /etc/passwd.

Here’s an example of a typical entry:

LOGINNAME:x:1001:1001:FULLNAME,,,:/home/DIRECTORY:/bin/bash
Enter fullscreen mode Exit fullscreen mode

That’s one line. Let me break it down field by field:

table

The UID (User ID) is what Ubuntu actually uses internally to track users, not the username.

Root always has UID 0. System services get UIDs in the 1–999 range typically, while regular users start from 1000 onwards.

The GID (Group ID) tells you which primary group the user belongs to. But here’s something that trips up many beginners: a user can belong to multiple groups. The primary group is just the one that’s assigned by default when creating files.

Read Full Article: https://serveravatar.com/list-users-and-groups-in-ubuntu

Top comments (0)