Enable/Disable Last Login Message on Linux using hushlogin

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
Enable/Disable Last Login Message on Linux using hushlogin
Enable/Disable Last Login Message on Linux using hushlogin
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any DEB or RPM based Linux system
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – 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.

The last login message and additional info is displayed when we log in
The last login message and additional info is displayed when we log in

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.

The last login message and additional info is now absent when logging in
The last login message and additional info is now absent when logging in

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.

Single user

  1. To permanently suppress a Last Login message as per on user basis, create a hidden .hushlogin file inside a user’s home directory. For example to suppress a Last Login message for the linuxconfig user, we would run this command:
    $ sudo touch /home/linuxconfig/.hushlogin
    
  2. Similarly to suppress a Last Login message for the root user, we would run this command:
    $ sudo touch /root/.hushlogin
    


System wide

Note: you will need to login to your system’s root account in order to run these commands.

  1. To permanently suppress a Last Login message for the entire system, first empty /var/log/lastlog file:
    # > /var/log/lastlog
    
  2. The above will clear all last login information. To make the change permanent disable write access to this file:
    # chattr +i /var/log/lastlog
    
  3. Optionally you can clear all login and bad login attempts information which is displayed by use of last and lastb commands. To do so run:
    # >/var/log/wtmp
    # >/var/log/btmp
    
  4. 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.

Last login message is gone but the other information remains
Last login message is gone but the other information remains

Closing Thoughts




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 .hushlogin file method.



Comments and Discussions
Linux Forum