How to list users in Linux

Ever wondered who’s on your Linux system? Whether you’re a tech pro or just getting started, knowing how to find the list of users is a handy skill. This guide is here to walk you through the simple steps of getting a user list on Linux.

In this how-to guide, we’ll cover some basic commands for discovering usernames, user IDs, and more. It’s not just about who’s who but understanding what’s going on behind the scenes in your Linux system.

Whether you’re keen on tightening security, fixing problems, or just curious about your Linux setup, this tutorial shares the Linux commands that will produce the information you’re looking for.

How to list users in Linux

You’ll need to access your Linux command line interface in order to complete the following steps. It would be helpful if you also have a basic understanding of Linux commands, but it’s not absolutely necessary.

1. Produce full list of users

how to, how to list users in linux

screenshot showing how to list users in Linux – produce full list

The easiest way to obtain a list of users in Linux is to use the getent command.

The getent command retrieves information from Linux’s databases, including information about users.

To obtain a full list of users, open your system’s command line interface and type the following command: getent passwd

This produces a list of users on the system and also includes (in a very abbreviated format) details about the user ID, group ID, user’s home folder, default shell, optional personal information, and whether the user has a password.

2. Produce list of user first names only

how to, how to list users in linux

screenshot showing how to list users in Linux – produce list of first names only

To produce a simpler user list, enter the command getent passwd | awk -F: ‘{ print $1}’

The awk tool is a versatile text processing tool in Linux and is mainly used for pattern scanning and processing.

By specifying print $1, we are instructing Linux to only return the first field of each entry.

The result is a list of first names only without all the additional information we got with the previous command.

However, you’ll notice in the example above, that there are many entries like systemd-network and systemd-timestamp which is probably not what you’re looking for when you’re trying to produce a list of users on the system.

This is because Linux does not distinguish between human users and system accounts created by applications.

We will look at producing a list of just the human users in the next couple of steps.

3. Understanding User Identifiers

how to, how to list users in linux

screenshot showing how to list users in Linux – User Identifiers

Users on the system are given a user identification number known as a UID. We can use this number to separate human and non-human users.

Enter the command grep -E ‘^UID_MIN|^UID_MAX’ /etc/login.defs to return the range of user identification numbers used by human users.

As you can see in the screenshot above, human users on my system have UIDs that are between 1000 and 60,000.

4. Producing a list of human users only

how to, how to list users in linux

screenshot showing how to list users in Linux – List of human users only

Now, you need to run the command to get a list of human users. Based on the answer I was given in the previous step, my command was getent passwd {1000..60000}.

You’ll need to ensure that the numbers in curly brackets in your command reflect the minimum and maximum UIDs you were provided with.

In my example above, I had a list of four people once I had removed all the non-human application and system users.

The getent command is just one of the ways that you can obtain information about users. If you are looking for specific user information, you might want to tailor your command to produce a filtered list that matches your requirements. Filtering or shortening your results is especially helpful if you have a large number of users on your system.

Producing a list of users in Linux can be beneficial for several reasons, including helping administrators identify who has accounts on the system or identifying which users own specific files or processes. Understanding Linux commands means that you can access information whenever you need it in the way that best suits you.

For more help with Linux, check out our guides on how to find CPU information in Linux, how to add users in Linux and how to find a file in Linux.

OTHER NEWS

16 minutes ago

Amazon Takes On Chinese Rivals Temu and Shein With Plans for New Discount Service

16 minutes ago

Bucs Best and Worst Offseason Moves

16 minutes ago

Theyab bin Mohamed bin Zayed attends announcement of Sandooq Al Watan summer programmes

16 minutes ago

Marilyn Monroe's former home declared a national landmark, saved from demolition

16 minutes ago

Tom Brady aiming for spot on US Olympic Track and Field team

16 minutes ago

Glastonbury Festival heat stroke warning issued as experts share red flag signs

16 minutes ago

Tennis-Wimbledon the final frontier for claycourt queen Swiatek to conquer

16 minutes ago

ESPN rates New York Jets roster 4th best in NFL

16 minutes ago

Calgary officials cautiously optimistic for July 5 water repair completion

16 minutes ago

House committee passes bill that would allow Medicare to cover weight loss drugs

16 minutes ago

Elated fans celebrate unveiling of Jenni Rivera's Hollywood Walk of Fame star

16 minutes ago

Jaguars quarterback Trevor Lawrence, wife expecting first child

16 minutes ago

Former AG Lynch recommends that Northwestern enhance hazing prevention training

16 minutes ago

Odyssey Sims scores 18 in her season debut, the Wings beat the Lynx to snap an 11-game losing streak

16 minutes ago

After split with NYC July 4 hot dog competition, Joey Chestnut heads to army base event in Texas

16 minutes ago

Paul Jubb enjoys best win of his career to progress in Majorca

16 minutes ago

Q1 GDP slows more than previously estimated as inflation concerns linger

20 minutes ago

Bogus employee retention claims are mucking up IRS operations

20 minutes ago

Sam’s Club is going after Costco through the hearts and wallets of Gen Z shoppers. ‘That generation believes it’s cool to save money,’ CEO says

20 minutes ago

Halfords says inflation remains a 'material headwind' as profits slip

20 minutes ago

Walgreens to close up to a quarter of its roughly 8,600 U.S. stores

20 minutes ago

Juventus finalising £42m deal to sign Douglas Luiz from Aston Villa as the Italian giants join Chelsea in the race for £70m-rated Nottingham Forest defender Murillo

20 minutes ago

Man United legend Roy Keane is spotted wearing an ARSENAL shirt as Ian Wright jokes that Red Devils fans 'are gonna do their nut in'

20 minutes ago

Everton defender Ben Godfrey close to securing move to Atalanta after Serie A side returned with improved bid in excess of £10m

20 minutes ago

2024 Copa America: Thursday's schedule and how to watch

21 minutes ago

Man arrested for giving state trooper the finger wins $239K settlement

21 minutes ago

New Jersey man killed by lightning while warning beachgoers about storm

25 minutes ago

C. Thomas Howell & Michelle Hurd Join Romantic Western ‘Where The Wind Blows’

27 minutes ago

Video: Joy Behar defends Biden's 'senior moments' on The View: 'He's overcome a lot of disabilities'

27 minutes ago

Video: Freight train derails in Illinois prompting mass evacuation for residents within a mile as hazmat teams rush to 'leaking cars'

27 minutes ago

Video: Joy Behar defends Biden's 'senior moments' on The View: 'He's overcome a lot of disabilities'

28 minutes ago

North Carolina rejects initial ballot access for RFK Jr., Cornel West in boost for Biden

28 minutes ago

Troubled suspect accused of threatening to kill GOP prez hopefuls found dead in NH

28 minutes ago

Biden camp dodges answering if president plans to use performance-enhancing drugs before debate

28 minutes ago

England vs Slovakia: Euro 2024 team news, TV channel and predicted line-up

28 minutes ago

Kevin De Bruyne tells Belgium teammates not to clap fans after players get booed

28 minutes ago

Rescuers pull injured passengers from train after derailment in northern Russia

28 minutes ago

He missed lunch - but Aussie Bolt can dine at Wimbledon

28 minutes ago

The world’s best holiday supermarkets – and why we love them

28 minutes ago

Report: Jimmy Butler Won’t Sign Extension With Heat Or Any Other Team