FreeBSD

How to list the system users in FreeBSD

This quick-tutorial is about listing all the users in FreeBSD using the FreeBSD CLI terminal. The same instructions can be used for other Unix-based operating systems, including OpenBSD, NetBSD, and Apple’s macOS. These Operating systems usually have a file dedicated to storing passwords for all users on the system, located in /etc/passwd in the case of FreeBSD. There are some systems with upscaled security protocols that may not have it in the /etc/passwd location. FreeBSD has the /etc.master.passwd for encrypted, high-security user accounts. In any case, this file can be accessed easily and will be used to acquire user account information in this tutorial.

List every user on your FreeBSD system

Fire up the command terminal and enter the commands below to obtain the list of user accounts.

$ cat /etc/passwd

$ more /etc/passwd
$ less /etc/passwd

With the passwd file accessed, we can discern the required info from the output. The last line in the file(see below) is crucial:

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

Let’s go over each of the elements in the file and see what it means.

The first element, vnstat is the user name for the account.

The next element is *:284:284, in which the symbol * signifies that the password is encrypted and is kept in a file of its own. Following the * is the number 284repeated twice, the first of which is the user, and the second is for the Group ID.

The third portion is the vnStat Network Monitor, which represents the account information.

/nonexistent signifies the home directory for each user account.

Lastly, the /usr/sbin/nologin section represents the login shell for the user.

Listing usernames with cut command

To acquire a simple list consisting of only the usernames, try the cut command:

$ cut -d: -f1 /etc/passwd

Using awk command to list users

Alternatively, you can use the awk command to obtain results similar to that of the cut command:

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

Displaying the username list with getent command

You can also use the getent command to access the passwd file.

$ getent passwd
$ getent passwd | more

To look up particular users with the getent command, add the username after the command.

$ getent passwd | grep younis

Searching particular usernames with grep command

To look for a particular user, try the grep command:

$ grep '^userNameHere' /etc/passwd
$ grep '^younis' /etc/passwd

Check user activity and login attempts on FreeBSD

You can also do this on OpenBSD, NetBSD, and other Unix OS. Type:

$ w

Or you can also use the command below

$ who

You should be displayed the account status for each user.

See active users and user groups on the server

To see what user accounts are active on your server, use the more/less/grep commands as under:

$ more /etc/group
$ less /etc/group
$ grep younis /etc/group

Obtain general info on accounts with logins

Type logins to see details on user accounts.

$ logins

Add the -a flag to see expiration dates on the user accounts:

$ logins -a

You can also look up details on a particular account with the –l flag:

$ logins -l younis

Similarly, to specify multiple accounts:

$ logins -l younis,root

To look up the home directory for all users, use the –x option with logins command:

$ logins -x

For a particular user, type in:

$ logins -x -l younis

Lookup low-security user accounts:

Use the -p option with the logins commands to see user accounts without passwords shown below:

$ logins -p

Summary

There are many reasons you might want to look up user accounts on your FreeBSD system. Perhaps you want to detect if anything fishy is going on, or maybe you’re just looking to survey the userbase on your system. We’ve listed several ways you can look up the usernames and account info in this tutorial. Most of the commands we listed extracted the information from the /etc/passwd file to present the output. Although this tutorial is intended for users of the FreeBSD operating system, users of other Unix operating systems such as macOS, NetBSD, OpenBSD, etc., can also follow the instructions here to achieve the same results.

About the author

Younis Said

I am a freelancing software project developer, a software engineering graduate and a content writer. I love working with Linux and open-source software.