How to check list of users in Unix

I

am a new Unix system user. How can I view system users in Unix operating system using the command line option?

 

The password file /etc/passwd contains one line for each user account. The passwd files are the local source of password information. Some system stores encrypted passwords in a separate file for security reasons. For example, on a FreeBSD you have /etc/master.passwd or on a Linux you have /etc/shadow file. The /etc/group file is the local source of group information/membership. This tutorial explains how to check the list of users in Unix operating system such as macOS, FreeBSD, OpenBSD, NetBSD, Unix-like system.

Command to check list of users in Unix

On a FreeBSD/OpenBSD/NetBSD and many other Unix-like system, just type the following cat command/more command/less command to get a list of all user accounts:

$ cat /etc/passwd

$ more /etc/passwd

$ less /etc/passwd

 

Sample outputs:

Understanding file format

Consider the last line:

vnstat:*:284:284:vnStat Network Monitor:/nonexistent:/usr/sbin/nologin

Where,

vnstat – User name

  • – Encrypted password is stored in a in a separate file
  • 284 – UID (User id)
  • 284 – GID (Group id)
  • vnStat Network Monitor – General information about the user
  • /nonexistent – User’s home directory
  • /usr/sbin/nologin – User’s login shell
  • How to just display a list of user names
  • Use the cut command as follows:
  • $ cut -d: -f1 /etc/passwd

OR use awk command:

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

 

Sample outputs:

root

daemon

operator

bin

build

sshd

….

 

_iscsid

_smtpq

_file

_radiusd

_eigrpd

_vmd

_tftp_proxy

_ftp_proxy

_sndiop

_syspatch

_slaacd

nobody

vivek

How do I search for a given user name such as vivek

Use the grep command as follows:

$ grep  ^userNameHere  /etc/passwd

$ grep  ^vivek  /etc/passwd

 

Sample outputs:

vivek:*:1001:1001:vivek:/home/vivek:/bin/tcsh

How to use getent command to find out a list of users

To get entries from administrative database such as /etc/passwd use the getent command as follows:

$ getent passwd

$ getent passwd | more

$ getent passwd | grep vivek

A note about macOS Unix users

If you are using a macOS, try the following command to check list of users in Unix cli (open the Terminal app and type the following bash command):

$ dscl . list /Users

 

OR

$ dscacheutil -q user

 

The dscl is a general-purpose utility for operating on Directory Service directory nodes.

How to find which Unix users are logged in and what they are doing

Type the following w command/who command:

$ w

 

OR

$ who

How do I see available list of groups on my server?

Type any one of the following command:

$ more /etc/group

$ less /etc/group

$ grep vivek /etc/group

See also

Linux Command: List All Users In The System

Man pages: passwd(5),group(5)

 

 

Leave a Reply

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