Bash .hushlogin, keep last login time and host

One way would be to add the following to ~/.ssh/rc, which contains commands to be run when you ssh into the machine:

lastlog -u $USER | perl -lane 'END{print "Last login: @F[3..6] $F[8] from $F[2]"}'

The command will get the time of your last login from lastlogin and then format it so that it looks like the original version. You can now touch ~/.hushlogin and you will still see that message.


Having your .bash_profile call lastlog -u "$USER" gets you something pretty close. Output looks like:

Username         Port     From             Latest
anthony          pts/7    192.168.XX.YY    Sun Feb  7 16:00:40 -0500 2016

where of course I redacted the IP address.

last -w -n 1 gets a similar record, but from a different database.

Tags:

Bash

Login

Motd