When logging into a Linux system from the terminal, especially via SSH, you may have noticed some output that gives information about the last login.
In addition, some systems will also show more information such as the last IP address to login, and some various system usage stats. If you find this message annoying or just plain unncessary, there is a simple configuration you can do in order to disable the message.
In this tutorial, we will go over the step by step instructions to enable or disable the last login message on all major Linux distributions, including the hushlogin method.
In this tutorial you will learn:
- How to enable or disable last login message on a per user basis
- How to enable or disable last login message system wide
|Category||Requirements, Conventions or Software Version Used|
|System||Any DEB or RPM based Linux system|
|Other||Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
Enable/Disable Last Login Message on Linux using hushlogin step by step instructions
As mentioned earlier, the last login message is displayed by default when you SSH into a machine, and sometimes displays additional information. Check the screenshot below to see all the output we get on our Ubuntu test system.
After suppressing the message, we eliminate the output completely. You can see this in the screenshot below, where a successful SSH login does not generate any extra output.
This gives a cleaner look and is also a bit faster.
It is possible to suppress the last login message on a per user basis or system wide. Depending on your preference, follow the appropriate set of step by step instructions below.
- To permanently suppress a Last Login message as per on user basis, create a hidden
.hushloginfile inside a user’s home directory. For example to suppress a Last Login message for the
linuxconfiguser, we would run this command:
$ sudo touch /home/linuxconfig/.hushlogin
- Similarly to suppress a Last Login message for the
rootuser, we would run this command:
$ sudo touch /root/.hushlogin
Note: you will need to login to your system’s root account in order to run these commands.
- To permanently suppress a Last Login message for the entire system, first empty
# > /var/log/lastlog
- The above will clear all last login information. To make the change permanent disable write access to this file:
# chattr +i /var/log/lastlog
- Optionally you can clear all login and bad login attempts information which is displayed by use of
lastbcommands. To do so run:
# >/var/log/wtmp # >/var/log/btmp
- Make the above file immutable if you wish the system to stop storing this information permanently:
# chattr +i /var/log/wtmp /var/log/btmp
With the above method, your system should stop showing the last login message, but may still display additional information. The screenshot below shows that the last login message is no longer shown on our Ubuntu system, yet the other various information is still displayed.
In this tutorial, we saw how to disable the last login message in Linux. These instructions should work for all major Linux distributions, namely RPM and DEB based systems. This configuration can be done on either a per user basis, or system wide. Be aware that some systems also display other information in addition to the last login message, and this needs to be disabled through the