How To Find Last Time The User Logged In On The System
Dear linux geeks,
In this tutorial I will teach you how to find out who has recently used the unix-like server, which terminals are used and the time users logged in and out of the server.
The command that we will use in order to accomplish the task is called last. It searches back through the file /var/log/wtmp and displays information about all users logged in and logged out. You can also specify names of users and tty’s in order to filter the output and show only those entries matching the specified input arguments.
The last command-line utility comes with many various options and can also give information about the reboot pseudouser which logs in each time the system is rebooted.
For example the last reboot command will show show a log of all reboots since the log file was created. How does the last command react when it catches a SIGINT signal?
According to the man page for the last utility, when it catches a SIGNIT signal it show how far it has searched through the file and will terminate. You can generate a SIGINT signal with control-C.
It is time to go into action. Open a new terminal (CTRL+ALT+T in Ubuntu Linux) and run the following command to get information on all users logged in and out in your unix-like system.
To display when a certain user has logged in type the following command.
Make sure to replace the username oltjano with the name of the user you are looking for. If you want full login and logout times and dates use the -F option to print them.
The -x option can be used to display the system shutdown entries and run level changes.
What about non-local logins? Can we get information about them? We are very lucky because Linux stores both the host name of the remote host and its IP number.
The -d option will help us.
The -i option displays the IP number in numbers-and-dots notation.
The -f option tells last to use a specific file instead of /var/log/wtmp.
last -f path_to_file
A very useful option is the -n option which can be used to tell the last command-line utility how many lines to show. The example shown below tells last to show only three lines.
last -n 3
Suppresses the display of the hostname field with the -R option.
A tool which is the same as last is the lastb command-line utility. It shows a log of the file /var/log/btmp, which contains all the bad login attempts.
As far as I am concerned you can use the same options we used with the last tool with the lastb utility but it is worth experimenting and playing by yourself.
Note: If wtmp and btmp files are not found you can create them with a simple touch command or by using your favourite text editor.
If these files do not exist the system will not log any information on them so make sure they exist before using the last and lastb utilities.
Like us on Facebook
We need your assistance to stay live
This week Top Posts
- Top Things To Do After Installing Ubuntu 13.10 'Saucy Salamander' : Ubuntu 13.10 Saucy Salamander will be released on coming October 17th with many new salient featur...0 comments |
- Install Fail2Ban On Ubuntu Server 13.04/13.10 : Introduction Fail2Ban is an intrusion prevention framework written in the Python programming l...0 comments |
- 5 Android Apps that’s Going to Make Running Your Business Less Stressful : Running a business can be very stressful. You have to think about team collaboration, making sure th...0 comments |
- Install Crashplan backup tool in Linux : CashPlan is an automated backup solution that either uses the CrashPlan Central server or any other ...0 comments |
- Install Corosync and Pacemaker On CentOS 6.5 : I will show you in this tutorial how to install your first cluster Corosync and the Linux Cluster Ma...0 comments |
- How To Upgrade From Ubuntu 13.04 Raring To Ubuntu 13.10 Saucy Salamander : Ubuntu 13.10 Saucy will be released on October 17th. Hope it will come with lot of improvements and ...0 comments |
- Install Uget Download Manager In Ubuntu, Fedora, Debian
- Download Elementary OS ‘Luna’ Official Wallpapers
- Install Power Commands 0.1.5 On Ubuntu 14.04/13.10/12.10/12.04
- 5 Android Apps that’s Going to Make Running Your Business Less Stressful
- Puppet agent Install Using Script
- Install Corosync and Pacemaker On CentOS 6.5
- Install Fail2Ban On Ubuntu Server 13.04/13.10
- How To Install Google Chrome in Fedora 20, 19, 18
- How to surf using Tor Browser Bundle
- New Games got Greenlit on Linux by Steam Today!
This work by unixmen.com is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
Copyright © 2008-2013 Unixmen.com .