Users currently logged on linux

4 Ways to Identify Who is Logged-In on Your Linux System

This article is written by Hari Haran.

As a system administrator, you may want to know who is on the system at any give point in time. You may also want to know what they are doing. In this article let us review 4 different methods to identify who is on your Linux system.

1. Get the running processes of logged-in user using w

  • Name of the user
  • User’s machine number or tty number
  • Remote machine address
  • User’s Login time
  • Idle time (not usable time)
  • Time used by all processes attached to the tty (JCPU time)
  • Time used by the current process (PCPU time)
  • Command currently getting executed by the users

Following options can be used for the w command:

  • -h Ignore the header information
  • -u Display the load average (uptime output)
  • -s Remove the JCPU, PCPU, and login time.
$ w 23:04:27 up 29 days, 7:51, 3 users, load average: 0.04, 0.06, 0.02 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT ramesh pts/0 dev-db-server 22:57 8.00s 0.05s 0.01s sshd: ramesh [priv] jason pts/1 dev-db-server 23:01 2:53 0.01s 0.01s -bash john pts/2 dev-db-server 23:04 0.00s 0.00s 0.00s w $ w -h ramesh pts/0 dev-db-server 22:57 17:43 2.52s 0.01s sshd: ramesh [priv] jason pts/1 dev-db-server 23:01 20:28 0.01s 0.01s -bash john pts/2 dev-db-server 23:04 0.00s 0.03s 0.00s w -h $ w -u 23:22:06 up 29 days, 8:08, 3 users, load average: 0.00, 0.00, 0.00 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT ramesh pts/0 dev-db-server 22:57 17:47 2.52s 2.49s top jason pts/1 dev-db-server 23:01 20:32 0.01s 0.01s -bash john pts/2 dev-db-server 23:04 0.00s 0.03s 0.00s w -u $ w -s 23:22:10 up 29 days, 8:08, 3 users, load average: 0.00, 0.00, 0.00 USER TTY FROM IDLE WHAT ramesh pts/0 dev-db-server 17:51 sshd: ramesh [priv] jason pts/1 dev-db-server 20:36 -bash john pts/2 dev-db-server 1.00s w -s

2. Get the user name and process of logged in user using who and users command

who command is used to get the list of the usernames who are currently logged in. Output of the who command contains the following columns: user name, tty number, date and time, machine address.

$ who ramesh pts/0 2009-03-28 22:57 (dev-db-server) jason pts/1 2009-03-28 23:01 (dev-db-server) john pts/2 2009-03-28 23:04 (dev-db-server)

To get a list of all usernames that are currently logged in, use the following:

$ who | cut -d' ' -f1 | sort | uniq john jason ramesh

Users Command

users command is used to print the user name who are all currently logged in the current host. It is one of the command don’t have any option other than help and version. If the user using, ‘n’ number of terminals, the user name will shown in ‘n’ number of time in the output.

$ users john jason ramesh

3. Get the username you are currently logged in using whoami

whoami command is used to print the loggedin user name.

$ whoami john

whoami command gives the same output as id -un as shown below:

$ id -un john

who am i command will display the logged-in user name and current tty details. The output of this command contains the following columns: logged-in user name, tty name, current time with date and ip-address from where this users initiated the connection.

$ who am i john pts/2 2009-03-28 23:04 (dev-db-server) $ who mom likes john pts/2 2009-03-28 23:04 (dev-db-server) Warning: Don't try "who mom hates" command.

Also, if you do su to some other user, this command will give the information about the logged in user name details.

Читайте также:  Remount all filesystems linux

4. Get the user login history at any time

last command will give login history for a specific username. If we don’t give any argument for this command, it will list login history for all users. By default this information will read from /var/log/wtmp file. The output of this command contains the following columns:

  • User name
  • Tty device number
  • Login date and time
  • Logout time
  • Total working time
$ last jason jason pts/0 dev-db-server Fri Mar 27 22:57 still logged in jason pts/0 dev-db-server Fri Mar 27 22:09 - 22:54 (00:45) jason pts/0 dev-db-server Wed Mar 25 19:58 - 22:26 (02:28) jason pts/1 dev-db-server Mon Mar 16 20:10 - 21:44 (01:33) jason pts/0 192.168.201.11 Fri Mar 13 08:35 - 16:46 (08:11) jason pts/1 192.168.201.12 Thu Mar 12 09:03 - 09:19 (00:15) jason pts/0 dev-db-server Wed Mar 11 20:11 - 20:50 (00:39

This article is written by Hari Haran. He is working in bk Systems (p) Ltd, and interested in contributing to the open source. The Geek Stuff welcomes your tips and guest articles.

Источник

How to List Current Logged-In Users on Linux

You can get a list of all the users who are currently logged in on your Linux system, provided you have the necessary permissions.

a person using a laptop on wooden stand

Readers like you help support MUO. When you make a purchase using links on our site, we may earn an affiliate commission. Read More.

Linux being a multi-user system allows multiple users to log in and run various programs at the same time. As a normal Linux user or system admin, you may sometimes need to check which users are currently logged into your system.

Читайте также:  Файловая система линукс минт

This information can be useful for various reasons such as for troubleshooting performance issues, monitoring user activity, or for simply checking who else is using the system.

There are several methods to list current logged-in users on Linux and see what they are doing.

1. The users Command

The users command in Linux lists all users who are currently logged in in alphabetic order.

Note that if a user has two login sessions, it will appear twice in the output.

The output below tells that there are three users logged into the system currently.

users command

2. Using the who Command

The who command prints the list of users currently logged into the system along with other information such as the terminal they’re using, login date and time, and IP address or hostname of the system if a user is on a remote machine.

To list current logged-in users on Linux, use the who command as follows:

who command

You can also use the who command with -a and -H flags to display idle time and PID of the user’s login shell:

who command output

3. Using the w Command

The w command in Linux shows logged-in users and their activities. It prints the list of users and their current processes in the command line.

The header in the output summarizes the status of the system which includes the current time, system uptime, number of logged-in users, and load average. Then for each logged-in user, it displays the user name, tty name, time of login, idle time, time used by all the processes (JCPU), time used by the current process (PCPU), and the current process the user is running.

Читайте также:  How to delete java linux

w command

4. Using the last Command

The last command lists current as well as past logged-in and logged-out users. The information it provides includes the name of users and terminals, the IP address of the system they are logged in from, and the date and time of login.

To find the list of users logged in currently, use the last command with the -p now option as follows:

last command

5. The finger Command

The finger command shows information about all the logged-in users on Linux including their username, tty, login date and time, and IP address. You can easily install finger on your Linux distribution using the default package managers.

On Debian-based distributions:

sudo apt-get install finger 

On RHEL-based distributions:

To display information on current logged-in users, run the finger command without any command-line options:

Источник

Оцените статью
Adblock
detector