Skip to main content

Command Palette

Search for a command to run...

How to See Users in Linux

Updated
6 min read

When you start working with Linux, one of the first things you might want to know is how to see users on the system. Whether you’re managing a server or just curious about who has access, knowing how to list users and check who is logged in is essential. In this article, I’ll guide you through simple commands and methods to see users in Linux, making it easy for you to manage or monitor your system.

You don’t need to be a Linux expert to understand these steps. I’ll explain everything clearly, so you can follow along and get the information you need quickly. Let’s dive into how you can see users in Linux, from listing all users to checking active sessions.

Understanding User Accounts in Linux

Before we jump into commands, it’s helpful to know what user accounts are in Linux. Linux systems have multiple user accounts, each with its own permissions and roles. These accounts can be:

  • Regular users: People who use the system for daily tasks.
  • System users: Accounts created for running services or system processes.
  • Root user: The superuser with full control over the system.

Knowing this helps you understand why some users appear in lists and others don’t. System users often have limited access and are hidden from regular user lists.

How to See All Users in Linux

If you want to see all users on your Linux system, you can check the /etc/passwd file. This file contains information about every user account.

To view all users, open your terminal and type:

cat /etc/passwd

This command shows a list of all user accounts with details like username, user ID, group ID, home directory, and default shell. The output looks like this:

root:x:0:0:root:/root:/bin/bash
john:x:1001:1001:John Doe:/home/john:/bin/bash

If you want to see just the usernames, use:

cut -d: -f1 /etc/passwd

This command extracts only the first field (username) from each line, giving you a clean list of all users.

Filtering Regular Users

Since /etc/passwd includes system users, you might want to filter only regular users. Usually, regular users have user IDs (UIDs) starting from 1000.

You can use this command to list regular users:

awk -F: '$3 >= 1000 {print $1}' /etc/passwd

This command prints usernames where the UID is 1000 or higher, which typically means regular users.

How to See Currently Logged-In Users

Sometimes, you want to know who is currently logged into the system. Linux provides several commands for this:

The who Command

The who command shows who is logged in right now:

who

It displays the username, terminal, login time, and sometimes the IP address if logged in remotely.

The w Command

The w command gives more detailed information about logged-in users and what they are doing:

w

You’ll see the username, terminal, login time, idle time, JCPU, PCPU, and the command they are running.

The users Command

If you want a quick list of logged-in usernames without extra details, use:

users

This command prints all logged-in users in a single line.

Checking User Login History

To see past login activity, Linux stores logs you can check with the last command:

last

This command shows a list of recent logins, including username, terminal, IP address, login time, and logout time.

You can limit the output to a specific user by typing:

last username

This helps you track user activity over time.

Using Graphical Tools to See Users

If you prefer a graphical interface, many Linux distributions offer user management tools. For example:

  • GNOME Users and Groups: Found in system settings, it shows all users and allows you to add or remove accounts.
  • KDE User Manager: Similar to GNOME’s tool but for KDE desktop environments.

These tools provide an easy way to see and manage users without using the terminal.

How to See User Groups in Linux

Users in Linux belong to groups that define their permissions. To see which groups a user belongs to, use:

groups username

For example:

groups john

This command lists all groups associated with the user “john.”

To see all groups on the system, check the /etc/group file:

cat /etc/group

This file lists all groups and their members.

How to Check User Details

If you want detailed information about a specific user, the id command is very useful:

id username

It shows the user ID (UID), primary group ID (GID), and all groups the user belongs to.

For example:

id john

Output might look like:

uid=1001(john) gid=1001(john) groups=1001(john),27(sudo)

This tells you that “john” has UID 1001, belongs to the group “john,” and is also part of the “sudo” group.

Managing Users: Adding and Removing Users

While this article focuses on seeing users, it’s helpful to know how to manage them.

Adding a User

To add a new user, use:

sudo adduser newusername

This command creates a new user and prompts you to set a password and other details.

Removing a User

To remove a user, use:

sudo deluser username

This deletes the user but leaves their home directory intact. To remove the home directory as well, add the --remove-home option:

sudo deluser --remove-home username

Summary Table of Useful Commands

CommandPurpose
cat /etc/passwdList all users with details
cut -d: -f1 /etc/passwdList all usernames only
awk -F: '$3 >= 1000 {print $1}' /etc/passwdList regular users (UID ≥ 1000)
whoShow currently logged-in users
wShow logged-in users and their activity
usersShow logged-in usernames in one line
lastShow login history
groups usernameShow groups for a specific user
id usernameShow detailed user info

Conclusion

Now you know several ways to see users in Linux, whether you want to list all users, check who is logged in, or view user groups. These commands and tools give you control and insight into your system’s user accounts. You can easily monitor user activity or manage accounts as needed.

Remember, Linux is flexible, and these commands work across most distributions. With this knowledge, you’ll feel more confident managing users and understanding your system better.

FAQs

How do I list all users on a Linux system?

You can list all users by viewing the /etc/passwd file with cat /etc/passwd or just usernames with cut -d: -f1 /etc/passwd.

How can I see who is currently logged in?

Use the who or w commands to see currently logged-in users and their activity.

What command shows user login history?

The last command displays recent login history for all users or a specific user.

How do I find out which groups a user belongs to?

Run groups username to see all groups associated with a user.

Can I see user information without root access?

Yes, most commands like who, w, users, and id work without root privileges. However, some user management commands require sudo access.

More from this blog

L

LinuxBloke | Linux Tips, Tricks & Troubleshooting

672 posts