List every user on your FreeBSD system
Fire up the command terminal and enter the commands below to obtain the list of user accounts.
$ 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:
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:
Using awk command to list users
Alternatively, you can use the awk command to obtain results similar to that of the cut command:
Displaying the username list with getent command
You can also use the getent command to access the passwd file.
$ getent passwd | more
To look up particular users with the getent command, add the username after the command.
Searching particular usernames with grep command
To look for a particular user, try the grep command:
$ 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:
Or you can also use the command below
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:
$ less /etc/group
$ grep younis /etc/group
Obtain general info on accounts with logins
Type logins to see details on user accounts.
Add the -a flag to see expiration dates on the user accounts:
You can also look up details on a particular account with the –l flag:
Similarly, to specify multiple accounts:
To look up the home directory for all users, use the –x option with logins command:
For a particular user, type in:
Lookup low-security user accounts:
Use the -p option with the logins commands to see user accounts without passwords shown below:
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.