How to List Users Logged in Linux
This post will guide you how to get current logged in users in Linux. How to see currently logged in users in your current Linux operating systems.
Show Who is Logged on And What They Are Doing
If you want to displays information about the user currently on your Linux system and their processes. And you can use a command called “w” to show who is logged on your system and what they are doing. Type:
$ w
Outputs:
devops@devops:~$ w 04:01:57 up 6:01, 2 users, load average: 0.04, 0.04, 0.01 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT devops pts/3 192.168.3.49 03:45 2.00s 0.10s 0.01s w devops :0 :0 23:05 ?xdm? 5:41 0.01s /usr/lib/gdm3/gdm-x-session --run-script env GNOME_SHELL_SESSION_MODE=ubuntu
The header shows, in this order, the current time, how long the system has been running, how many users are currently logged on, and the system load averages for the past 1, 5, and 15 minutes.
Show Who is Logged on
If you want to print information about users who are currently logged in. and you can type the following “who” command:
$ who
Or
$ who -a
Outputs:
evops@devops:~$ who devops pts/3 2019-09-09 03:45 (192.168.3.49) devops :0 2019-09-08 23:05 (:0) devops@devops:~$ who -a system boot 2019-09-08 22:00 run-level 5 2019-09-08 22:00 devops + pts/3 2019-09-09 03:45 . 9791 (192.168.3.49) devops ? :0 2019-09-08 23:05 ? 4562 (:0)
Show who is Currently Logged in
If you want to find out who you are currently logged in your current shell, just using “whoami” command, type:
$ whoami
Outputs:
devops@devops:~$ whoami devops
You can also use another command to show who you are currently logged in on your Linux system, type:
$ id
Outputs:
devops@devops:~$ id uid=1000(devops) gid=1000(devops) groups=1000(devops),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),116(lpadmin),126(sambashare),128(lxd)
If you want to get more information about those commands, and you can see man pages for those commands, type:
$ man w $ man who $ man whoami $ man id
All user names are stored in /etc/passwd file, and you can list all names with cat command, type:
$ cat /etc/passwd
Outputs:
devops@devops:~$ cat /etc/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin proxy:x:13:13:proxy:/bin:/usr/sbin/nologin www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin backup:x:34:34:backup:/var/backups:/usr/sbin/nologin list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin systemd-network:x:100:102:systemd Network Management,,,:/run/systemd/netif:/usr/sbin/nologin systemd-resolve:x:101:103:systemd Resolver,,,:/run/systemd/resolve:/usr/sbin/nologin syslog:x:102:106::/home/syslog:/usr/sbin/nologin messagebus:x:103:107::/nonexistent:/usr/sbin/nologin _apt:x:104:65534::/nonexistent:/usr/sbin/nologin uuidd:x:105:111::/run/uuidd:/usr/sbin/nologin avahi-autoipd:x:106:112:Avahi autoip daemon,,,:/var/lib/avahi-autoipd:/usr/sbin/nologin usbmux:x:107:46:usbmux daemon,,,:/var/lib/usbmux:/usr/sbin/nologin dnsmasq:x:108:65534:dnsmasq,,,:/var/lib/misc:/usr/sbin/nologin rtkit:x:109:114:RealtimeKit,,,:/proc:/usr/sbin/nologin cups-pk-helper:x:110:116:user for cups-pk-helper service,,,:/home/cups-pk-helper:/usr/sbin/nologin speech-dispatcher:x:111:29:Speech Dispatcher,,,:/var/run/speech-dispatcher:/bin/false whoopsie:x:112:117::/nonexistent:/bin/false kernoops:x:113:65534:Kernel Oops Tracking Daemon,,,:/:/usr/sbin/nologin saned:x:114:119::/var/lib/saned:/usr/sbin/nologin pulse:x:115:120:PulseAudio daemon,,,:/var/run/pulse:/usr/sbin/nologin avahi:x:116:122:Avahi mDNS daemon,,,:/var/run/avahi-daemon:/usr/sbin/nologin colord:x:117:123:colord colour management daemon,,,:/var/lib/colord:/usr/sbin/nologin hplip:x:118:7:HPLIP system user,,,:/var/run/hplip:/bin/false geoclue:x:119:124::/var/lib/geoclue:/usr/sbin/nologin gnome-initial-setup:x:120:65534::/run/gnome-initial-setup/:/bin/false gdm:x:121:125:Gnome Display Manager:/var/lib/gdm3:/bin/false devops:x:1000:1000:devops,,,:/home/devops:/bin/bash sshd:x:122:65534::/run/sshd:/usr/sbin/nologin mysql:x:123:127:MySQL Server,,,:/nonexistent:/bin/false lxd:x:124:65534::/var/lib/lxd/:/bin/false wildfly:x:999:999::/opt/wildfly:/sbin/nologin couchdb:x:125:129:CouchDB Administrator,,,:/opt/couchdb:/bin/bash plex:x:126:130::/var/lib/plexmediaserver:/bin/bash cassandra:x:127:131:Cassandra database,,,:/var/lib/cassandra:/usr/sbin/nologin ntp:x:128:132::/nonexistent:/usr/sbin/nologin