What command is used to show who is currently logged in and what they are doing?
To check information about users who are currently logged into the system, we use the who command in the Linux system. Show
The who command is used to display the users logged into the system. The who command related to the w command that is used to display information about the users currently on the machine and their processes. SyntaxThe general syntax of the who command is as follows − who [OPTION]... [ FILE | ARGUMENT1 ARGUMENT2 ] Brief description of options available in the who command. Sr.No.Option & Description1-a, --allSame as -b -d --login -p -r -t -T -u 2-b, --boot Display last rebooted time of system 3-d, --dead Display dead processes and details 4-H, --heading Display line of column headings 5-l, --login Display system login processes 6--lookup Attempt to canonicalize hostnames via DNS 7-q, --count Display all login names and number of users logged on 8-s, --short Display only name of user, line, and time (default) 9-t, --time Display last system clock change 10-T, -w, --mesg Add user’s message status as +, - or ? 11-u, --users Display list users logged in 12--message Same as -T 13--writable Same as -T 14--help Displays a help message and then exits. 15--version It gives info about the version and then exits. To displays the name of users currently logged in, terminal line numbers, login time of the users in the system, and remote hostname of the user in the Linux system, we use the who command without any options and arguments as shown below. vikash@tutorialspoint:~$ who vikash :0 2021-01-11 09:40 (:0) To enhance the output and print information in standard input, we use -H option with the who command as shown in below. vikash@tutorialspoint:~$ who -H NAME LINE TIME COMMENT vikash :0 2021-01-11 09:40 (:0) To display the last booted time of the Linux/Unix system using the terminal, we use -b or -- boot option with the who command as shown below. vikash@tutorialspoint:~$ who –boot System boot 2021-01-11 09:37 Or vikash@tutorialspoint:~$ who -b System boot 2021-01-11 09:37 To display the current login user in the Linux system, we use the whoami command without any option and arguments as shown below. vikash@tutorialspoint:~$ whoami vikash To display more information about the command, we use --help option with the who command as shown in below. Linux is a multi-user operating system that allows multiple users to access the system at the same time. As a Linux system administrator, you have to check who are logged into the system before starting to work on any issues, especially when you have a team members spread across multiple locations. Because, if multiple users are making the changes in the same configuration file, it may create additional problems. So, make sure nobody is currently working on the issue before you take it up. To avoid these things, we need to check who all are logged into the system and what are they doing. In this tutorial, we will show you how to check the current logged-in users with several commands in Linux.
Knowing more than one command to find the same information will not hurt you, and do not hesitate to check the alternate options. Method-1: Checking logged-in users with ‘w’ command‘w command’ shows who are logged-in and what are they doing. It displays information about current users on the machine by reading the file # who root pts/0 2017-05-31 15:22 (203.99.204.108)0. w command output comes with header information, which displays system activity such as current time, system up time, how many users are currently logged-in, and the system load (which averages for the past 1, 5, and 15 minutes) w command contains the following values: login user name, tty number, remote host, user’s login time, idle time, JCPU (time used by all processes attached to the tty), PCPU (time used by the current process), and which commands are currently being executed by the users. Please see below: # w 17:13:34 up 1:52, 1 user, load average: 0.11, 0.18, 0.15 USER TTY FROM [email protected] IDLE JCPU PCPU WHAT root pts/0 203.99.204.108 15:22 6.00s 0.18s 0.00s w Method-2: Identifying who is Logged-in using ‘who’ command‘who command’ shows information about users who are currently logged in. It uses ‘/var/run/utmp’ & ‘/var/log/wtmp’ files to get those details.
who command output contains the following values such as login user name, tty number, date & time, and remote host. # who root pts/0 2017-05-31 15:22 (203.99.204.108) Method-3: How to see Logged in users with ‘whoami’ commandwhoami is basically the concatenation of the strings “who”,”am”,”i” as whoami. It displays the username of the current user. It’s similar to running the id command with the options -un as shown below: # whoami root Also, when you use whoami with space (who am i) that will give you a different output. It will display more details compared to whoami command as shown below: $ who am i daygeek pts/1 2019-06-17 22:01 (192.168.1.6) “id” command prints user and group information for a specified username, but we can add # who root pts/0 2017-05-31 15:22 (203.99.204.108)3 option with the “id” command to display all the currently logged-in users as shown below: # id -un root Method-4: Using users command‘users command’ prints the usernames of users currently logged in to the current host. It uses # who root pts/0 2017-05-31 15:22 (203.99.204.108)5 files to get the details as shown below: # users root Method-5: Show currently logged-in users with ‘finger’ command‘finger’ is a utility, which allows users to see the information about system users (login name, home directory, name, how long they’ve been logged in to the system, etc.). Finger utility is available in all major Linux distributions, but it doesn’t come installed by default. Use distribution package manager to install “finger” on your system. $ finger Login Name Tty Idle Login Time Office Office Phone magi daygeek tty7 7 Jun 1 16:05 (203.99.204.108) Bonus TipsAdditionally, you can use the following methods to identify who all are logged-in on your system: Bonus Tips-1: How to show current logged-in users with ‘last’ command‘last command’ shows a list of last logged in users by searching the data from # who root pts/0 2017-05-31 15:22 (203.99.204.108)5 file. Also, it shows the system reboot information. “last” command output contains login user name, tty number, remote host, date, login time, logout time, and the total duration (working time). Run the following command to show who all logged-in today. Also, you can check who’s currently logged in by filtering with the “still logged in” string. # last -p today linuxgee tty2 tty2 Thu Mar 4 14:27 gone - no logout linuxgee : : Thu Mar 4 14:27 gone - no logout Bonus Tips-2: Manual Way to check who’s logged-inLast but not the least, we can get a list of logged in users on Linux machine manually by using less commands or more commands or head command or tail command, followed by the log file location. User authentication logs are located @ # who root pts/0 2017-05-31 15:22 (203.99.204.108)7 for RHEL based systems & # who root pts/0 2017-05-31 15:22 (203.99.204.108)8 for Debian based systems. $ head -5 /var/log/auth.log Jun 1 16:05:01 daygeek CRON[1944]: pam_unix(cron:session): session opened for user root by (uid=0) Jun 1 16:05:01 daygeek CRON[1944]: pam_unix(cron:session): session closed for user root Jun 1 16:05:44 daygeek lightdm: pam_unix(lightdm-greeter:session): session closed for user lightdm Jun 1 16:05:44 daygeek lightdm: pam_unix(lightdm:session): session opened for user magi by (uid=0) Jun 1 16:05:44 daygeek systemd: pam_unix(systemd-user:session): session opened for user magi by (uid=0) Over to YouIn this guide, you learnt how to find out who all are currently logged-in on your Linux system employing different commands. If you found this article helpful, please do share with your friends and spread the knowledge. Please feel free to comment below if you have any queries/concerns. We will get back to you as soon as we can. Happy learning! Which command is used for who are currently logged in and what they are doing?Description : The who command is used to get information about currently logged in user on to system.
What command is used to display currently logged user?The who command displays information about all users currently on the local system. The following information is displayed: login name, tty, date and time of login. Typing who am i or who am I displays your login name, tty, date and time you logged in.
|