As a Linux system administrator, regularly checking the login dates and times of your server's users is essential. This helps you monitor active and inactive users, their login times, and session durations.
1. w
Command
The w
command in Linux helps you find out who is logged in and what they are doing on the system. It is a commonly used tool to display information about current users and their processes.
The w
command provides various details, including:
- Current time
- System uptime
- Number of logged-in users
- System load averages for the past 1, 5, and 15 minutes
Example Output:
In this output, there are two users (root and test) logged into the Ubuntu server. The w
command displays the following details for each user:
- Login name
- TTY name
- IP address of the logged-in user
- Login time
- Idle time
- JCPU time (total time used by all processes attached to the TTY)
- PCPU time (time used by the current process)
- Command line of the current process
To display details for a specific user, for example, test
, use:
w test
2. who
Command
The who
command shows information about users currently logged in to the Linux machine.
Example Output:
Additional Options:
Filter details for a specific user with grep
:
who | grep test
Display information for the current terminal session:
who am i
Display all available information of current logins using the -a
flag:
who -a
[upl-image-preview url=https://www.community.vpssell.com/assets/files/2024-07-30/1722333758-346567-output-2.png]
3. users
Command
The users
command prints the usernames of users currently logged in to the system.
4. last
Command
The last
command displays all users that have logged in and out of a Linux machine since the /var/log/wtmp
file was created.
last
Example Output:
There are various commands to find the last logged-in users on your VPS. Use the commands provided in this guide or explore other commands available on the internet.