How to List User Accounts on Ubuntu 18.04 | 16.04

How to List User Accounts on Ubuntu 18.04 16.04

This post shows users and new students that how to List User Accounts on Ubuntu 18.04 | 16.04. If you’re going to List User Accounts on Ubuntu then this post is ideal for you.

Ubuntu is a Linux Operating System based on Debian and mostly composed of non-profit(free) and open-source software. It is a complete Linux operating system that compatible with desktops, laptops, server and other devices. Ubuntu is Open Source so it is freely available for both community and professional support.

Linux is an operating system, like Windows OS, iOS, and Mac OS. Linux is one of the most popular operating system on the planet, Android is also powered by Linux OS(operating system). An operating system is software that manages all hardware resources associated with desktop or laptop. In simple words, the OS(operating system) manages communication between software and hardware.

If you are a learner and looking for a Linux distribution for Learning then Ubuntu Linux Operating System is best for you as a beginning.

In this post shows that how to list all user accounts on Ubuntu. There are many ways to find out user accounts on Ubuntu. Here in this post we are going to use below two methods to find out all user accounts on Ubuntu.

Method 1: List User in the passwd file

One of the method for find out user accounts on Ubuntu is to view the content of the /etc/passwd file.

The above file is store user account information . So for view all user accounts on the your system simply run the below commands :

less /etc/passwd

When you run the above commands, it will list the content of the /etc/passwd file similar as a below:

root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
........

It is very confusing to read the content of file for new users. In the above list, each line is contains  a single account identity.

There are seven fields in the single line that contain the following:

  • User name
  • Encrypted password (x means, password is stored in the /etc/shadow file)
  • User ID number (UID)
  • User’s group ID number (GID)
  • Full name of the user (GECOS)
  • User home directory
  • Login shell (defaults to /bin/bash)

If you only want to list the account names (User names) then simply run the below commands :

awk -F: '{ print $1}' /etc/passwd

The above command show the list that contains only the account names on the your system beginning with the root account.

root
daemon
bin
sys
sync
games
man
......

Method 2: Get User List via Getent Tool

Run the below commands to get the lists of users via the getent tool :

getent passwd

The above command should list all user accounts same content as above Method :

root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
........

Getent Tool lists the content of the /etc/passwd file using the database info stored in the /etc/nsswitch.conf file.

If you find any error and issue in above steps , please use comment box below to report.

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top