How do I see all users logged in Linux?
A Linux system admin should keep an eye on who is currently logged into the Linux system and what are they up to. We already knew how to find the last logged in users in Linux. How would you identify who is logged on your Linux system at the moment and what they are doing? Easy! This tutorial lists various methods to find currently logged in users in Linux. Show
Contents
1. Find currently logged in users in Linux using $ w ostechnix 08:51:36 up 37 min, 2 users, load average: 1.12, 1.06, 0.76 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT ostechni pts/1 192.168.225.37 08:42 0.00s 0.09s 0.01s w ostech4 commandIn Linux operating systems, there is special, single letter command called 5 that helps you to find who is logged on and what they are doing in the system. This is the most commonly used command line tool to display the information about the users currently on the server, and their processes.The 4 command is often useful when you are administering a Linux server that is frequently being accessed by many users. You can track all of them without having to install any additional tools or applications.The 4 command shows various useful details including the following:
The 4 command fetches information about who is currently logged on from the 9 file and retrieves the process information from the 0 file.Now let us see how to use 4 command to display who is logged in on your Linux machine and what they are doing.The typical usage of 4 command is:
When you run w command without any options, it will display all currently logged in users in your Linux system:
Sample output: Find currently logged in users in Linux using 4 commandAs you can see in the above output, currently there are two users (sk and ostechni) logged into my Ubuntu server. The 4 command displays the following details for the individual users:
If you want to display the details of a specific logged in user (E.g. ostechnix), the command would be:
You can omit the header from the output using 5 option:
You can also display IP address instead of hostname for 6 (remote hostname) field using 7 option:
You may not want to print all the details. If so, you can exclude the login time, JCPU or PCPU times using 8 ( 9) option:
For more details, check man pages:
Or, refer help section:
2. Display all logged in users using $ w -i0 commandThe 0 command is yet another command line tool to display information about users who are currently logged in a Linux machine.If you run 0 command without any options, it will display all logged in users:
Sample output: 0Display currently logged in users in Linux using who commandAs you see in the above output, 0 command shows the username, type of the terminal device (E.g. 4 or 5) on which the session took place, boot time and the source IP address from which the user logged in.You can filter details for a specific user with 6 command: 1The above command will find if the given user ostechnix is logged in or not. If you want to display information only for the current terminal session, run: 2Please note the spaces between the words. If you execute the above command without any spaces, it will only display the username: 3The 0 command has few other options to get customised output.For example, you can display all available information of current logins using 8 flag: 4Sample output: 5To display all available information with column headers, use 9 flag: 6For more details, refer the man pages and help section of who command using any one of the following commands: 7 83. Print logged in users with $ w -s 09:02:50 up 48 min, 2 users, load average: 0.31, 0.79, 0.84 USER TTY FROM IDLE WHAT sk tty1 - 21:02 -bash ostechni pts/1 192.168.225.37 1.00s w -s0 commandThe 0 command prints the user names of users currently logged in to the current host system.To display a list of all logged in users in a Linux machine, run: 9To get help, run any one of the following commands: 0 14. View logged in users with $ w -s 09:02:50 up 48 min, 2 users, load average: 0.31, 0.79, 0.84 USER TTY FROM IDLE WHAT sk tty1 - 21:02 -bash ostechni pts/1 192.168.225.37 1.00s w -s2 commandThe 2 command usually displays all the users that have ever logged in and out of a Linux machine since the 4 file was created. 2The list of currently logged in users are shown at the top. 3For help, see man pages or use 5 option: 4 55. Find who is logged in a Linux system using id commandThe 6 command is used to print user and group information for the specified USER, or for the current user when USER is omitted.To print the currently logged in user in the current session, run 6 command with 8 options: 6This is same as the 9 command.To get help, do: 7 8All of the aforementioned tools are available by default in most Linux distributions. There is one more command line tool available to find who is logged in a Linux system. It is not installed by default, but available in the default repositories of most Linux distributions. 6. List logged in users with finger commandFinger is a command line user information lookup utility. It displays the user's login name, real name, terminal name and write status, idle time, login time, office location and office phone number etc. The finger program is not installed by default in some Linux distributions. You can install finger in Debian, Ubuntu systems using apt package manager like below: 9Once installed, run finger command to find logged in users in your Linux system: 0Sample output: 1Display information about a specific user: 2Sample output: 3These are a few methods to find the currently logged in users in a Linux system. Knowing who is logged in and finding what they are doing in your system can be helpful at troubleshooting times. I hope one of the aforementioned methods will help you out. |