What users are logged in linux

How to show current logged in users in Linux

All user names are stored in /etc/passwd file and can be displayed with help of cat command or grep command/egrep command:
cat /etc/passwd
grep ‘^userNameHere’ /etc/passwd
grep ‘^tom’ /etc/passwd
Let us see all examples and usage in details.

How to show current logged in users in Linux

  • The current time ( 22:11:17 )
  • How long the Linux server has been running (18 days)
  • How many users are currently logged on Linux (2 users)
  • The system load averages for the past 1, 5, and 15 minutes (1.01, 1.04, 1.05)

The following info displayed for each current logged in user:

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

  • sweta – Login name
  • pts/10 – The tty name
  • minitx – The remote host/desktop/laptop name
  • 22:11 – Login time
  • 5.00s – Idle time
  • 0.04s – JCPU (it the time used by all processes attached to the tty. It does not include past background jobs, but does include currently running background jobs.)
  • 0.02s – PCPU (it is the time used by the current process, named in the “what” field.)
  • vim replicant.py – The command line of their current process

Find out who you are currently logged in as on Linux

Execute the following command:
whoami
Another option is to just type the following id command:
id

Use the whoami and id commands to find out who you are currently logged in as on Linux based system

Linux show who is logged on

Conclusion

This page showed how to find out current logged in users in Linux and what they are doing from the terminal. For more info see man pages using the man command:
man w
man who
man whoami

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Источник

UNIX / Linux List Current Logged In Users

H ow do I print the user names of users currently logged in to the current UNIX / Linux host / server from a command prompt?

You need to use any one of the following command line tools to list currently logged in users on Linux or Unix-like systems.

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements w or who command on Linux and Unix
Est. reading time 5m

The following two file keep login records on Linux and Unix-like systems:

  • /var/run/utmp – Keeps and allows us to discover information about who is currently using the system. Please note that there may be more L inux and Unix users currently using the system, because not all programs use utmp logging . In other words, poorly written app, hidden programs, malware, and other bad stuff will not be useful to list logged in users.
  • /var/log/wtmp – Keeps records all logins and logouts.

We simply cannot read these files using cat command/grep command/egrep command as file is in binary database format. Hence, we use the following commands to find currently logged in users in Linux and Unix-like systems.

Linux Command To List Current Logged In Users

  1. w command – Shows information about the users currently on the machine, and their processes.
  2. who command – Display information about users who are currently logged in.
  3. users command – See the login names of the users currently on the system, in sorted order, space separated, on a single line. It reads all information from /var/run/utmp file.

How to find currently logged in users in Linux

Open a terminal (or login into remote server using ssh command) and type the following commands.

Using w command to list current logged in users under Unix or Linux

Open the terminal application and then type the w command:
$ w

Fig.01: w command in action.

Understanding w command outputs

From Fig.01 we see the following for each user:

  • USER – Linux or Unix login name.
  • TTY – The tty name.
  • FROM The remote host or IP address.
  • @Login – Login time.
  • IDEL – Idle time.
  • JCPU – The JCPU time is the time used by all processes attached to the tty. However, it does not include past background jobs, but does include currently running background jobs.
  • PCPU – The PCPU time is the time used by the current process, named in the “what” field.
  • WHAT – The command line of that users current process.

To see info about a user named tom, enter:
$ w tom
Tell w command not print header:
$ w -h
$ w —no-header
We can also ignore current process username by passing the -u or —no-current to the w command:
$ w -u
$ w —no-current
Want to see remote hostname field? Try:
$ w -f
Show IP address instead of hostname for from field:
$ w -i
We can also old style output. In other words old outputs prints blank space for idle times less than one minute:
$ w -o

Display all logged in users using who command

The who command works on all Unix like operating systems such as macOS, *BSD, Linux and so on. The syntax is pretty simple:
# who
Here is what we see:

The who command displays the following information:

  • root – The username
  • pts/0 – Type of the terminal device. In this example, we see pseudoterminal pts/0 used by root user.
  • 2013-03-12 15:10 – User login date and time stamp.
  • (10.1.3.177) – The remote IP address from which the user logged into this server.

We can pass the -a option to who command as follows to see time of last system boot, display dead processes, system login processes, active processes spawned by init/systemd, print current runlevel, print last system clock change, show user’s message status, and list users logged in to Linux or Unix box:
# who -a
Here is output from older Linux system (pre Systemd):

Sample outputs from Systemd based Linux sysetem:

Getting help with the whois command

You can pass the following options to the who command (taken from the who command man page):

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

users command

Open a terminal or login over the ssh session and enter the following users command:
$ users
Output who is currently logged:

Vieing logged in users with last command

Want to see a listing of last logged in users? Use the last command to lookup binary database called /var/log/wtmp and displays a list of all users logged in (and out) since that file was created. For instance see history for user named ‘vivek’:
$ last vivek

Источник

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

w command is used to show logged-in user names and what they are doing. The information will be read from /var/run/utmp file. The output of the w command contains the following columns:

  • 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.

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.

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

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.

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

whoami command is used to print the loggedin user name.

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

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.

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

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

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 users currently logged in to Linux

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 /var/run/utmp , and their processes /proc .

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:

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.

  • /var/run/utmp: It contains information about the users who are currently logged onto the system. Who command is used to fetch the information from the file.
  • /var/log/wtmp: It contains historical utmp. It keeps the users login and logout history. The last command uses this file to display the information.

who command output contains the following values such as login user name, tty number, date & time, and remote host.

Method-3: How to see Logged in users with ‘whoami’ command

whoami 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:

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:

“id” command prints user and group information for a specified username, but we can add -un option with the “id” command to display all the currently logged-in users as shown below:

Method-4: Using users command

‘users command’ prints the usernames of users currently logged in to the current host. It uses /var/run/utmp & /var/log/wtmp files to get the details as shown below:

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.

Bonus Tips

Additionally, 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 /var/log/wtmp 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.

Bonus Tips-2: Manual Way to check who’s logged-in

Last 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 @ /var/log/secure for RHEL based systems & /var/log/auth.log for Debian based systems.

Over to You

In 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!

Источник

Читайте также:  Обновить драйвера ноутбука асер windows 10
Оцените статью