Thursday, November 17, 2022
HomeNetworkingMethods to have a look at logged in customers on Linux

Methods to have a look at logged in customers on Linux


There are fairly a number of methods on Linux to get an inventory of the customers logged into the system and see what they’re doing. The instructions described on this article all present very helpful data.

customers

The customers command shows a easy record of logged-in customers. On this instance, one consumer is logged in twice and is, subsequently, listed twice.

$ customers
nemo popeye shs shs

Observe that the customers are listed in alphabetical order.

who

The who command gives further data. The login terminal is recognized together with the login date and time. The ultimate subject shows the terminal or the IP deal with of the connecting system.

$ who
shs      tty2         2022-11-12 10:54 (tty2)
nemo     pts/0        2022-11-15 11:07 (192.168.0.3)
shs      pts/5        2022-11-15 10:41 (192.168.0.3)
popeye   pts/2        2022-11-15 11:12 (192.168.0.3)

w

The w command gives much more data on logged-in customers. The primary line of output reveals the present time, how lengthy the system has been up, the variety of logged-in customers, and the 1-, 5- and 15-minute load averages. This data gives you a fast view of how busy the system is.

The traces following the column headings present usernames, login instances, how lengthy the periods have been idle, the time utilized by all processes related to the consumer’s tty (JCPU), the time utilized by the present course of for the consumer’s terminal (PCPU), and the command being run. If the session is at the moment idle, you’ll merely see the shell that’s in use (e.g., -bash).

The w command gives a fast view of how closely the system is getting used and the place many of the exercise is coming from.

$ w
 12:16:09 up 3 days, 15:10,  4 customers,  load common: 0.00, 0.01, 0.01
USER     TTY        LOGIN@   IDLE   JCPU   PCPU WHAT
shs      tty2      Sat13    3days  0.05s  0.05s /usr/libexec/gnome-session-bina
nemo     pts/0     11:07    4:38   0.04s  0.04s -bash
shs      pts/5     10:41    0.00s  0.10s  0.00s w
popeye   pts/2     11:12    1:02m  0.02s  0.02s -bash

final

The final command shows an inventory of consumer logins with the newest logins first. To see the newest logins, you should utilize a command like this one:

$ final | head -3
popeye   pts/2        192.168.0.3      Tue Nov 15 11:12   nonetheless logged in
nemo     pts/0        192.168.0.3      Tue Nov 15 11:07   nonetheless logged in
shs      pts/5        192.168.0.3      Tue Nov 15 10:41   nonetheless logged in

To see how far the at the moment obtainable login data reaches again, pipe the final command’s output to the tail command.

$ final | tail -3
reboot   system boot  5.14.10-300.fc35 Mon Jun  6 15:57 - 16:55  (00:58)

wtmp begins Mon Jun  6 15:57:30 2022

ps

ps command just like the one beneath will present an inventory of the processes a consumer is operating. Including the grep -v `whoami` merely omits the command you’ll be operating to create the record. You possibly can simply grep together with your username (e.g., grep -v shs), however the command proven works for anybody.

$ ps -ef | grep nemo | grep -v `whoami`
root      124982     787  0 11:07 ?        00:00:00 sshd: nemo [priv]
nemo      124990       1  0 11:07 ?        00:00:00 /usr/lib/systemd/systemd --user
nemo      124999  124990  0 11:07 ?        00:00:00 (sd-pam)
nemo      125018  124982  0 11:07 ?        00:00:00 sshd: nemo@pts/0
nemo      125025  125018  0 11:07 pts/0    00:00:00 -bash

By utilizing grep to pick out course of particulars by the primary subject, you will notice solely that consumer’s processes. The ^nemo argument selects solely the output traces that start with “nemo”.

$ ps -ef | grep ^nemo
nemo      124990       1  0 11:07 ?        00:00:00 /usr/lib/systemd/systemd --user
nemo      124999  124990  0 11:07 ?        00:00:00 (sd-pam)
nemo      125018  124982  0 11:07 ?        00:00:00 sshd: nemo@pts/0
nemo      125025  125018  0 11:07 pts/0    00:00:00 -bash

id

You should utilize the id command to show some further particulars on a consumer. This consists of the consumer’s UID (consumer id), GID (group id), and an inventory of the teams that the consumer is a member of.

$ id nemo
uid=1012(nemo) gid=1012(nemo) teams=1012(nemo),900(techs)

finger

You may also get some data on customers with the finger command.

$ finger nemo
Login: nemo                             Title: Nemo the Fish
Listing: /residence/nemo                   Shell: /bin/bash
On since Tue Nov 15 11:07 (EST) on pts/0 from 192.168.0.3
   1 minute 44 seconds idle
No mail.
No Plan.

uptime

The uptime command will let you know how lengthy the system has been up since its final reboot and the variety of consumer at the moment logged in. Just like the w command, it additionally gives the system load averages.

$ uptime
 12:07:47 up 3 days, 15:01,  4 customers,  load common: 0.07, 0.13, 0.06

prime and htop

If you wish to see whether or not a specific consumer’s processes are having an affect on system efficiency, you should utilize a software like prime or htop to find out whether or not any consumer processes are making important use of system assets. Utilizing both of those instruments, urgent the Shift+M keys will kind the output by reminiscence utilization. Utilizing Shift+P will kind the output by processor utilization. The instance beneath reveals nemo as a big consumer of the system CPU and reminiscence, however the system is just not extremely impacted.

prime - 12:41:48 up 3 days, 15:35,  4 customers,  load common: 0.14, 0.06, 0.02
Duties: 262 whole,   1 operating, 261 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.8 us,  0.5 sy,  0.0 ni, 98.5 id,  0.2 wa,  0.0 hello,  0.0 si,  0.0 st
MiB Mem :   5926.3 whole,    145.1 free,   2273.7 used,   3507.5 buff/cache
MiB Swap:   5926.0 whole,   5926.0 free,      0.0 used.   3374.3 avail Mem

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
   3059 root      20   0  259104  29984   8428 S   1.7   0.5  11:11.01 sssd_kcm
 134122 nemo      20   0  222648   3976   3524 R   1.3   0.2   0:00.07 loop <===
 128996 shs       20   0  225824   4436   3564 R   0.3   0.1   0:00.63 prime
      1 root      20   0  172392  17720  11256 S   0.0   0.3   0:03.51 systemd
…

Wrap-up

Instructions for viewing logged-in customers, the processes they’re operating and the way they could affect efficiency will turn out to be useful whether or not you are attempting to get an understanding of how a Linux system is getting used or trying to discover the supply of a efficiency downside.

Copyright © 2022 IDG Communications, Inc.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments