Uploaded by heru handoko

How to check list of users in Unix - nixCraft

advertisement
🐧 nixCraft → Howto → FreeBSD → How to check list of users in Unix
How to check list of users in Unix
Author: Vivek Gite • Last updated: July 17, 2020 • 4 comments
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,
1.
vnstat
– User name
2.
*
3.
284
– UID (User id)
4.
284
– GID (Group id)
5.
vnStat Network Monitor
6.
/nonexistent
7.
/usr/sbin/nologin
– Encrypted password is stored in a in a separate file
– General information about the user
– User’s home directory
– 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
Display Unix account information using logins
command
The logins command shows information about user and system accounts. All
you have to do is type the following command:
$ logins
Patreon supporters only guides 🤓
➔ No ads and tracking
➔ In-depth guides for developers and sysadmins at Opensourceflare✨
➔ Join my Patreon to support independent content creators and start
reading latest guides:
↪ How to set up Redis sentinel cluster on Ubuntu or Debian Linux
↪ How To Set Up SSH Keys With YubiKey as two-factor
authentication (U2F/FIDO2)
↪ How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
↪ A podman tutorial for beginners – part I (run Linux containers
without Docker and in daemonless mode)
↪ How to protect Linux against rogue USB devices using USBGuard
↪ If your domain is not sending email, set these DNS settings to avoid
spoofing and phishing
Join Patreon ➔
root
0
wheel
0
Charlie &
toor
0
wheel
0
Bourne-again Superuser
daemon
1
daemon
1
Owner of many system pro
operator
2
operator
5
System &
bin
3
bin
7
Binaries Commands and So
tty
4
nogroup
65533
Tty Sandbox
kmem
5
nogroup
65533
KMem Sandbox
games
7
games
13
Games pseudo-user
news
8
news
8
News Subsystem
man
9
man
9
Mister Man Pages
sshd
22
sshd
22
Secure Shell Daemon
smmsp
25
smmsp
25
Sendmail Submission Use
mailnull
26
mailnull
26
Sendmail Default User
bind
53
bind
53
Bind Sandbox
unbound
59
unbound
59
Unbound DNS Resolver
proxy
62
proxy
62
Packet Filter pseudo-use
_pflogd
64
_pflogd
64
pflogd privsep user
_dhcp
65
_dhcp
65
dhcp programs
uucp
66
uucp
66
UUCP pseudo-user
pop
68
mail
6
Post Office Owner
auditdistd
78
audit
77
Auditdistd unprivileged
www
80
www
80
World Wide Web Owner
_ypldap
160
_ypldap
160
YP LDAP unprivileged use
hast
845
hast
845
HAST unprivileged user
tests
977
tests
977
Unprivileged user for te
vivek
1001
vivek
1001
Vivek Gite
nobody
65534
nobody
65534
Unprivileged user
To get information about the password change and user account expiration
times, run:
$ logins -a
Only find and display information about tom and jerry accounts:
$ logins -l userName
$ logins -l tom,jerry
Want to see Unix user accounts with no password? Pass the
-p
option:
$ logins -p
Finally, we can see information about each account’s home directory and shell
such as csh, ksh, bash and more:
$ logins -x
$ logins -x -l vivek
vivek
1001
vivek
1001
Vivek Gite
/home/vivek
/bin/tcsh
Conclusion
Linux Command: List All Users In The System
Man pages: logins(1)
🐧 Get the latest tutorials on Linux, Open Source & DevOps via
RSS feed ➔
Weekly email newsletter ➔
🔎 To search, type & hit enter...
Related Tutorials
How to check open ports in Linux using the CLI
Linux List All Users In The System Command
Linux / Unix AWK: Read a Text File
UNIX / Linux List Current Logged In Users
How to check and list installed packages in CentOS Linux
How to use yum command on CentOS/RHEL
Linux / Unix: users Command Examples
Category
Download
managers
List of Unix and Linux commands
wget
Documentation help • mandb • man • pinfo
Disk space
analyzers
File
Management
Firewall
Linux Desktop
apps
df • duf • ncdu • pydf
cat • cp • less • mkdir • more • tree
Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 •
Ubuntu 18.04 • Ubuntu 20.04
Skype • Spotify • VLC 3
Modern utilities bat • exa
Network Utilities NetHogs • dig • host • ip • nmap
OpenVPN
CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 •
Ubuntu 20.04
Category
Package
Manager
List of Unix and Linux commands
apk • apt
Processes bg • chroot • cron • disown • fg • glances • gtop • iotop • jobs • killall •
Management kill • pidof • pstree • pwdx • time • vtop
Searching ag • grep • whereis • which
Shell builtins compgen • echo • printf
Text processing cut • rev
User groups • id • lastcomm • last • lid/libuser-lid • logname • members •
Information users • whoami • who • w
WireGuard VPN Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04
Comments on this entry are closed.
nasewei • Jan 2, 2018 @ 12:44
what about “logins”-command?
link
🐧 Vivek Gite • Jul 17, 2020 @ 18:06
I added logins command too. Thanks!
link
Bibo • Jul 18, 2020 @ 17:23
Hi Vivek,
I checked the logins cmd on Debian 10 (Buster) …
it seems to me the cmd is here “lslogins” and the
output looks a little bit different …
link
🐧 Vivek Gite • Jul 18, 2020 @ 18:15
yes, that is expected as GNU/Linux is not Unix.
link
Comments are closed. Still have questions? Post it on our forum
Next FAQ: How to install curl on FreeBSD using pkg command
Previous FAQ: How to check running process in Linux using command line
 
🔎 To search, type & hit enter...
FEATURED ARTICLES
1
30 Cool Open Source Software I Discovered in 2013
2
30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
3
Top 32 Nmap Command Examples For Linux Sys/Network Admins
4
25 PHP Security Best Practices For Linux Sys Admins
5
30 Linux System Monitoring Tools Every SysAdmin Should Know
6
40 Linux Server Hardening Security Tips
7
Linux: 25 Iptables Netfilter Firewall Examples For New SysAdmins
8
Top 20 OpenSSH Server Best Security Practices
9
Top 25 Nginx Web Server Best Security Practices
10
My 10 UNIX Command Line Mistakes
SIGN UP FOR MY NEWSLETTER
➔
Linux shell scripting tutorial
➔
RSS/Feed
➔
About nixCraft
 
©2002-2021 nixCraft • Privacy • ToS • Contact/Email • Corporate patron Linode
Download