We are learning how to get all logged in user name in a Linux server you need administrative privileges to execute commands cover here.
There are many ways to list logged in user on a Linux machine. Here I am covering my three favourite method for this purpose. All this command run with any fedora based system like Red Head Linux , Centos, Rocky Linux, Amla linux etc.
1. lastlog : you can use list command to know all login user. this command uses file available in /var/log/lastlog. This command read data from the mentioned file and present in a human readable from
lastlog | grep -v 'Never'
2. W command : This is more preferable way to get all logged in user, it uses file mentioned on lastlog command and file situated on /proc folders. it will display more information about last login user like ip address, hostname and running program etc. Here is the screenshot after running w command without specifying any option.
If you want to see ip details you can use -i switch, here is the output while using -in switch:
3. who command: we can use who command to know the all logged in user name. it is more like w command. Here is the output of who command with -aH switch.
Here -a switch tell program to include all and -H switch instruct to include column header.
Comments