See logged in user 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.

Читайте также:  Linux time real user sys

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 see Logged in Users in Linux

Check who is logged in your Linux system with these simple commands. You can also get additional information about logged in users such as their log in time.

Have you ever been curious about who is logged in to your Linux system? You can always list all the users on your Linux system but not all of them would be logged in all the time.

If you are on a multi-user Linux environment like a Linux server, checking logged in users could be useful and fun at the same time.

In this tutorial, I’ll show you various ways you list logged in users in Linux.

4 Commands to see logged users on Linux

Logged In Users Linux

Almost all these commands rely on the data stored in the /var or /proc directory. If you know a little about the directory structure in Linux, you know that these two directories contains data about the running processes on your system.

1. Use w command to see logged in users in Linux

Can it get any simpler than this? Just type a single letter command in the terminal and it will show the currently logged users in Linux.

And here is the output for the w command:

[email protected]:~$ w 09:54:54 up 26 min, 3 users, load average: 0.00, 0.00, 0.00 USER TTY FROM [email protected] IDLE JCPU PCPU WHAT root pts/0 202.91.87.114 09:37 21.00s 0.00s 0.00s -bash abhi pts/1 202.91.87.114 09:47 0.00s 0.00s 0.00s w rohini pts/2 157.43.53.142 09:48 6:13 0.00s 0.00s -bash

Let me explain a few terms in the output of the w command. The same terms would be used in other commands as well.

Читайте также:  Дистрибутивы linux для планшетов

TTY gives you information about the terminal used to log on. pts means pseudo terminal slave which indicates that the user logged in via SSH connection.

It shows the IP address of the user’s computer and login time. You can also see for how long a user has been idle (slacking at work? :D).

JCPU is the time used by all processes attached to the TTY and PCPU is the time used by the current process running by the user. You can see this current process under the WHAT column.

2. Check who is logged in with who command

Who command is another simple one. Just type who and it will show who is logged on to your Linux system currently.

You can also see the login time and the IP address of the logged on user.

[email protected]:~$ who root pts/0 Aug 6 09:37 (202.91.87.114) abhi pts/1 Aug 6 09:47 (202.91.87.114) rohini pts/2 Aug 6 09:48 (157.43.53.142)

3. Just get logged in users with users command

All the commands you saw so far give you a lot of information about the logged in users. If you are working on a script and want to know just the name of the logged in users, parsing the output of those commands would be an additional and somewhat complicated task.

This is where the users command can help you. This command only outputs the logged in users, nothing else.

4. Using finger command to see logged in users

You may need to install finger command first because not all Linux distributions have it installed by default.

It is available in the universe repository of Ubuntu and you can install it with this command:

Once installed, just type finger in terminal:

And you’ll see who is logged in on your Linux system.

[email protected]:~$ finger Login Name Tty Idle Login Time Office Office Phone abhi Abhishek pts/1 Aug 6 09:47 (202.91.87.114) rohini Rohini Rachita pts/2 13 Aug 6 09:48 (157.43.53.142) root root *pts/0 Aug 6 09:37 (202.91.87.114)

Bonus Tip: see who logged on your system since last reboot

What you saw so far was about the currently logged in users. How would you know if a user logged out?

The last command in Linux gives you information about all the users who logged in to the system since the last reboot. It will also show the log in and log out time of the logged out users.

Here’s the output of the last command which is self-explanatory I believe.

[email protected]:~$ last rohini pts/3 157.43.53.142 Tue Aug 6 10:05 - 10:05 (00:00) rohini pts/2 157.43.53.142 Tue Aug 6 09:48 still logged in abhi pts/1 202.91.87.114 Tue Aug 6 09:47 still logged in root pts/0 202.91.87.114 Tue Aug 6 09:37 still logged in reboot system boot 4.15.0-52-generi Tue Aug 6 09:28 still running wtmp begins Tue Aug 6 09:28:43 2019

I hope this quick tutorial helped you in finding the users currently logged on to your Linux system. If you know some other way to do it, please share your trick with us in the comment section.

Источник

See Logged in Users on Ubuntu Linux

Sagar Sharma

Logged in users in Ubuntu

Linux from its core is made to have multiple users especially if we consider servers.

Читайте также:  Astra linux размер экрана

And there are several reasons why you want to check the currently logged-in users such as to check for unauthorized access.

The easiest way to check the logged-in users in your Ubuntu machine is to use the users command:

use the users command to list currently logged in users in ubuntu

And as you can see, it brought the list of currently logged-in users.

Want to know more ways to list logged-in users? Here you have it.

How to find logged-in users in Ubuntu

Here, I will share some interesting utilities that will offer additional information such as the time of logging in, IP address, and a lot more.

So let’s get started with my personal favorite.

Use the w command to find logged-in users in Ubuntu

The w command can show you the currently logged-in users and what they are doing.

All you need to do is enter w in your terminal and it will bring the list of logged-in users:

find currently logged in users in ubuntu using the w command

  • TTY will show the terminal used to log in. Here, tty7 indicates the user is logged in via the native terminal whereas the pts is used to indicate the ssh connection used to log in.
  • FROM column will show the IP address of the remote connection.
  • [email protected] will show the time of logging in.
  • IDLE will show how long the user has kept the system idle.
  • JPCU is the time used by all the processes that are attached to tty.
  • PCPU will show the time taken by the current process that is shown in the WHAT section sitting right in the corner.
  • WHAT will show the name of the current process.

And the above description will remain the same for all the utilities that I’m about to show you.

Use the who command to find logged-in users in Ubuntu

The who utility can show who is currently logged in to your system (pretty generic name right?).

While you can execute the who without an additional option, I would recommend using the -H option to have headings for each column:

use the who command to find currently logged in users in ubuntu

Here, the LINE section will show the type of terminal used to log in (similar to TTY in the earlier command) and the COMMENT column will show the IP address.

Use the finger utility to find logged-in users in Ubuntu

Want to have the most detailed output in terms of finding logged-in users? Use the finger utility.

Unlike the other utilities, it does not come pre-installed and you’d need to use the following command for installation:

Now, all you need to do is execute the following:

use the finger utility to find curently logged in users in ubuntu

And you’d notice that it has some extra columns showing details such as full name, phone, etc.

The reason behind the extra details is that finger is a user information lookup utility so if you added extra details while adding a user in Linux, those details will reflect here.

Bonus: List logged-in users since the last reboot

If you want to know who logged in to your system from the last reboot, you can use the last command:

List logged-in users since the last reboot in ubuntu

The last command will simply look for the binary database located at /var/log/wtmp to list users who logged in since the last time system was rebooted.

Wrapping Up

This was a quick article on how you can find the currently logged-in users in Ubuntu.

And if you are using any other utilities, let me know through the comments.

Источник

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