Learn How to Display Users Info and Activity In Linux
When you are administrating bunch of groups and users on your Linux system, you might be wondering how to monitor their configuration and activity on the system. Linux provides various commands, which gives you comprehensive overview of users and groups activity. So in this article will learn 10 useful ways to display users info and activity in Linux.
`
So let’s start to learn these 10 different ways to keep an eye on what’s going on inside your system.
1. users Linux Command
users – This is quick and simple command to prints currently logged in users on your host without showing much details.
[root@lx1 ~]# users BroExperts Hafiz root
Output is showing currently three users are logged in on this system.
2. id Linux Command
id – Prints information of current user such as id, group id and which group user belongs, if user provided it will show details of specified user. see examples below
Without specifying user
[root@lx1 ~]# id uid=0(root) gid=0(root) groups=0(root)
BroExperts user specified
[root@lx1 ~]# id BroExperts uid=1001(BroExperts) gid=1001(BroExperts) groups=1001(BroExperts)
3. lslogins Linux Command
lslogins – display information about known users in the system. -u switch will show only user accounts
[root@lx1 ~]# lslogins -u UID USER PROC PWD-LOCK PWD-DENY LAST-LOGIN GECOS 0 root 92 0 0 11:54:31 root 1000 pxyuser 3 0 1 1001 BroExperts 1 0 0 13:28:47 System Admin 1002 Hafiz 3 0 0 11:56:45 Hafiz Haider
4. finger Linux Command
finger – display comprehensive information about users in the system. Its not pre-installed on many Linux distributions. So run following command to install this utility on your system
RHEL/CentOS
sudo yum install finger
Debian/Ubuntu
sudo apt install finger
finger command
[root@lx1 ~]# finger BroExperts Login: BroExperts Name: System Admin Directory: /home/BroExperts Shell: /bin/bash On since Tue Sep 26 13:28 (+04) on pts/1 from 192.168.2.119 10 minutes 3 seconds idle No mail. No Plan.
This command output shows user’s home directory, shell, login name and time and other information as showing above.
5. last Linux Command
last – shows the list of most recently logged in users
Running last command without any option will display below output. Each line first column represents username.
[root@lx1 ~]# last Ali pts/3 192.168.1.106 Tue Sep 19 04:12 still logged in BroExper pts/1 192.168.1.106 Tue Sep 19 04:12 still logged in Hafiz pts/0 192.168.1.106 Tue Sep 19 04:12 still logged in root pts/2 192.168.1.106 Tue Sep 19 02:47 still logged in root pts/1 192.168.1.106 Tue Sep 19 01:25 - 04:02 (02:36) root pts/0 192.168.1.106 Tue Sep 19 00:26 - 03:40 (03:13) reboot system boot 3.10.0-693.2.2.e Tue Sep 19 00:24 - 04:45 (04:20) root pts/0 :0 Tue Sep 19 00:23 - 00:24 (00:00) root :0 :0 Tue Sep 19 00:22 - crash (00:02) reboot system boot 3.10.0-693.2.2.e Tue Sep 19 00:12 - 04:45 (04:32) BroExper pts/0 :0 Mon Sep 18 23:59 - 00:12 (00:13) BroExper :0 :0 Mon Sep 18 23:58 - down (00:13) reboot system boot 3.10.0-693.el7.x Mon Sep 18 23:46 - 00:12 (00:26) wtmp begins Mon Sep 18 23:46:34 2017
6. w Linux Command
w – It is a quick and easy way to see who is logged in and what they are doing on system, such as their processes.
[root@lx1 ~]# w 04:59:04 up 4:34, 4 users, load average: 0.00, 0.01, 0.05 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT Hafiz pts/0 192.168.1.106 04:12 4:16 0.08s 0.00s tail -f /var/log/dmesg BroExper pts/1 192.168.1.106 04:12 4:40 0.55s 0.53s top root pts/2 192.168.1.106 02:47 0.00s 0.23s 0.00s w Ali pts/3 192.168.1.106 04:12 4:40 0.23s 0.19s watch ifconfig
6. ac Linux Command
ac – This command print stats about how long users have been connected. It will generate report of connect time in hours based on the logins/logouts. If you type ac without any argument it will display total connect time.
Note:- Before you use ac command, you need to install psacct package, it contains several other utilities also to monitor Linux systems such as lastcomm, that we can use to display previously executed commands by users. You can see the usage of lastcomm below in the list.
First Install psacct package
For RHEL / CentOS use:
# yum install psacct -y
For Ubuntu / Debian use:
# apt-get install acct
Start psacct Service & Enable on System Boot
Type following commands:
# systemctl restart psacct systemctl enable psacct
Now you are ready to execute ac command to monitor users connected time.
As mentioned earlier it will display total connect time, if you type ac without any argument. as showing below
[root@lx1 ~]# ac total 11.46
Display total time based on day.
[root@lx1 ~]# ac -d Sep 18 total 0.03 Today total 11.87
Display total time based on each user.
[root@lx1 ~]# ac -p root 8.35 BroExperts 1.52 Ali 1.07 Hafiz 1.08 total 12.01
7. lastcomm Linux Command
lastcomm – This useful command will display information about previously executed commands by Linux users.If no arguments given, lastcomm will show info about all of the commands in acct (the record file: /var/account/pacct). You can search activities by username, command executed by users or terminal-names.
Show commands executed by BroExperts
[root@lx1 ~]# lastcomm --user BroExperts clear BroExper pts/1 0.00 secs Sat Jul 29 05:12 ifconfig BroExper pts/1 0.00 secs Sat Jul 29 05:12 ls BroExper pts/1 0.00 secs Sat Jul 29 05:11 clear BroExper pts/1 0.00 secs Sat Jul 29 05:11 ls BroExper pts/1 0.00 secs Sat Jul 29 05:11
Search activities by command name
[root@lx1 ~]# lastcomm rm rm root pts/0 0.00 secs Sat Jul 29 06:19 rm root pts/0 0.00 secs Sat Jul 29 06:19 rm root pts/0 0.00 secs Sat Jul 29 06:18 rm BroExper pts/1 0.00 secs Sat Jul 29 06:18 rm BroExper pts/1 0.00 secs Sat Jul 29 06:18 rm BroExper pts/1 0.00 secs Sat Jul 29 06:18 rm BroExper pts/1 0.00 secs Sat Jul 29 06:18 rm BroExper pts/1 0.00 secs Sat Jul 29 06:17
8. who Linux Command
who – Used to display who is logged on to the system. It also shows terminal information they are connected from.
[root@lx1 ~]# who root tty1 2017-07-29 04:00 root pts/0 2017-07-29 04:00 (192.168.1.106) BroExperts pts/1 2017-07-29 05:10 (192.168.1.106) root pts/2 2017-07-29 05:10 (192.168.1.106)
9. groups Linux Command
groups – display all the groups a user belongs.
[root@lx1 ~]# groups BroExperts BroExperts : BroExperts webproject mobileapp linux
10. ps Linux Command
ps – It is process status command (ps) displays information about active processes on system. We will see how to use this command to monitor process running by a specific user
[root@lx1 ~]# ps -u BroExperts PID TTY TIME CMD 9014 ? 00:00:00 sshd 9015 pts/1 00:00:00 bash 9288 pts/1 00:00:00 ping 9291 ? 00:00:00 sshd 9292 pts/3 00:00:00 bash 9312 pts/3 00:00:00 top
That’s all. We have explained various useful commands to monitor/ display users info and activity in Linux, if you know any other way or command to monitor users activity please tell us in comments form below. Thanks