Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

At my company, when I log into some servers, my last login and a huge banner are displayed:

me@my-laptop$ ssh the-server
Last login: Mon Feb  8 18:54:36 2016 from my-laptop.company.com 
************************************************************************
*                                                                      *
*       C O M P A N Y    I N F O R M A T I O N   S Y S T E M S         *
*                                                                      *
* !WARNING!         Your connection has been logged          !WARNING! *
*                                                                      *
* This system is for the use of authorized personnel only.             *
* Individuals using this *computer system without authorization,       *
* or in excess of their authority as determined by the Company         *
* Code of Ethics and  Acceptable Use Policy, are subject to having all *
* of their activities on this system monitored, recorded and/or        *
* terminated by system personnel.                                      *
* If such monitoring reveals possible evidence of criminal  activity,  *
* Company may provide said evidence to law enforcement officials,      *
* in compliance with its confidentiality obligations and all           *
* applicable national laws/regulations with regards to data privacy.   *
*                                                                      *
*      This device is maintained by Company Department                 *
*                  admin@company.com                                   *
************************************************************************
me@the-server$ 

Of course, I don't want this huge banner displayed every time I login, but I would like to keep the last login time and host displayed.

If I use touch ~/.hushlogin, the banner is not displayed but I also loose the the last login information. In fact, nothing at all is displayed:

ssh the-server
me@the-server$

How do I remove the banner but keep the last login time and host, like this:

 ssh the-server
 Last login: Mon Feb  8 18:54:36 2016 from my-laptop.company.com
 me@the-server$
share|improve this question
up vote 8 down vote accepted

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.

share|improve this answer
    
Nice one. I finally went for last -w | grep "$USER" | head -n1 | perl -lane 'END{print "Last login: @F[3..6] $F[8] from $F[2]"}' because lastlog was truncating my hostname. – Xion345 Feb 8 at 18:33
1  
@Xion345 Rather than grepping for your username (which might get you someone else with a longer username that contains yours), you can use last -w "$USER" | ... there – Monty Harder Feb 8 at 21:36
1  
You also might want to know if the /etc/motd changes, so could also add: cmp /etc/motd ~/.hushlogin.motd || cat /etc/motd && cp /etc/motd ~/.hushlogin.motd – rrauenza Feb 8 at 22:55

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.