Networking/Computing Tips/Tricks

Rate this content:
5 of 5 - 2 votes
Thank you for rating this article.

An essential function when administering a Linux system is configuring and managing users and groups. I cover adding users in this article:

That said, viewing users is done using a few simple commands.

How To View Users on a Linux System

Every user on a Linux system, whether created as an account for a real human being or associated with a particular service or system function, is stored in a file called "/etc/passwd".
The "/etc/passwd" file contains information about the users on the system and each line describes a distinct user.  Lets view this file with the following command:

less /etc/passwd

You should get an output that looks like this (your system will be different):

2022 04 06 6 09 11

I have indicated the human/system users with arrows.  The other users are processes. Some of these other users might be created for use by daemons and background services. 

Each line is an independent user name, and then the rest is broken up into fields. These fields are delimited by the colon (:) character.  Let's take a look at a single line to see what information it contains:


The fields of information are separated by a colon (:) character. There are seven fields on each line in a typical Linux "/etc/passwd" file:

  1. root: This is the sccount username.
  2. x: Placeholder for password information.  The password is obtained from the "/etc/shadow" file.
  3. 0: User ID.  Each user has a unique ID that identifies them on the system.  The root user is always referenced by user ID 0.
  4. 0: Group ID.  Each group has a unique group ID.  Each user has a "primary" group that is used as the group by default.  Again, the root group's ID is always 0.
  5. root: Comment field.  This field can be used to describe the user or user's function.  This can be anything from contact information for the user, to descriptions of the service the account was made for.
  6. /root: Home directory.  For regular users, this would usually be "/home/<span class="highlight">username</span>".  For root, this is "/root".
  7. /bin/bash: User shell. This field contains the shell that will be spawned or the command that will be run when the user logs in.

If the only field that we are really interested in at the moment is the first one, we can get this list without wading through the entire "/etc/passwd" by typing:

cut -d : -f 1 /etc/passwd

How To Find Which Users Are Logged In

Many times, it will be more useful to find out which users are active on your system.  The "w" command is a simple way to list all of the currently logged in users, their log in time, and what the command they are currently using:

2022 04 06 6 36 54

The first line contains system uptime information. The following lines describe who is logged in - in my example I am the only user on the system.

An simpler alternative that provides similar information is the "who" command:

2022 04 06 6 39 29

How To View Available Groups on a Linux System

The corresponding file for discovering system groups is "/etc/group".  You can fiew the entire file by typing the following command:

less /etc/group

Your output will look different, but you should get something like this:

2022 04 06 6 30 16

The output will be a list of each group on the system, one per line.  You can see that many of the group names mirror the users we discovered on our system. This is part of a configuration scheme called " user private groups", or UPG.  User private groups create a private group for each user and set that group as the primary group. The umask is then changed from 022 to 002.  This allows for more flexibility in shared directories by setting a flag called setgid, which gives files inside the directory the same group owner as the directory itself. While this configuration is useful, it is outside of the scope of this article.

As before, you can pare down the information from the "/etc/group" file by using the cut command:

cut -d : -f 1 /etc/group

Summing Up

Hopefully I have done some justice to the Linux useradd command. Let us all know other options you use and why you use them in the comments below. The same instructions apply for any Linux distribution, including Ubuntu, CentOS, RHEL, Debian, Fedora, and Arch Linux.

I hope you find this article and its content helpful.  Comments are welcomed below.  If you would like to see more articles like this, please support us by clicking the patron link where you will receive free bonus access to courses and more, or simply buying us a cup of coffee!, and all comments are welcome!

Add comment


Did you learn something?
Did I save you time? 

Buy me a coffeeBuy me a coffee!

Find by Tag

5G Networks 6LoWLAN 6LoWPAN 802.11 802.11ah 802.11ax 802.11ay 802.11az ACL Addressing Analysis Ansible Architecture ARP Assessment AToM Backup Bandwidth BGP Bibliography Biography Briefings CBRS CellStream Cellular Central Office Cheat Sheet Chrome Cisco Clock Cloud Computer Consulting CPI Data Center Data Networking Decryption DHCPv4 DHCPv6 Display Filter DNS Documentation ECMP EIGRP Ethernet Flipping the Certification Model Follow Me Fragmentation Git GNS3 Google GQUIC Hands-On History Home Network HTTPS ICMP ICMPv6 IEEE 802.11p IEEE 802.15.4 In A Day Internet IOS Classic IoT IPv4 IPv6 L2 Switch L2VPN L3VPN LDP Learning Services Linux LLN Logging LoL M-BGP MAC MAC OSx Macro Microsoft mininet Monitoring Monitor Mode MPLS Multicast Name Resolution Netflow NetMon netsh Networking Network Science nmap Npcap nslookup Online Learning Online School OpenFlow OSPF OSPFv2 OSPFv3 OSX Parrot Passwords pcap pcap-ng PIM Ping Policy Port Mirror POTS POTS to Pipes PPP Profile Profiles Programming Project Management Python QoS QUIC Requirements RFC RIP Routing RPL RSVP SAS SDN Security Self Certification Service Provider Small Business Smartport SONET Span Port SSH SSL Subnetting T-Shark TCP TCP/IP Telco Telecom 101 Telecommunications Telnet Terminal TLS Tools Traceroute Traffic Analysis Traffic Engineering Training Travel Troubleshooting Tunnel Utility Video Virtualbox Virtualization Voice VoIP VXLAN Webex Wi-Fi Wi-Fi 4 Wi-Fi 5 Wi-Fi 6 Wi-Fi 6/6E Windows Wireless Wireless 5G Wireshark Wireshark Tip WLAN ZigBee Zoom

Twitter Feed