Bash .hushlogin, mantieni l'ultimo tempo di accesso e host


19

Nella mia azienda, quando accedo ad alcuni server, vengono visualizzati il ​​mio ultimo accesso e un enorme banner:

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$ 

Ovviamente, non voglio che questo enorme banner venga visualizzato ogni volta che eseguo l'accesso, ma vorrei mantenere l'ultimo orario di accesso e l'host visualizzati .

Se uso touch ~/.hushlogin, il banner non viene visualizzato ma perdo anche le ultime informazioni di accesso . In realtà, non viene visualizzato nulla:

ssh the-server
me@the-server$

Come rimuovo il banner ma mantengo l'ultimo tempo di accesso e host, in questo modo:

 ssh the-server
 Last login: Mon Feb  8 18:54:36 2016 from my-laptop.company.com
 me@the-server$

Risposte:


15

Un modo sarebbe quello di aggiungere quanto segue ~/.ssh/rc, che contiene i comandi da eseguire quando si entra nella macchina:

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

Il comando otterrà l'ora dell'ultimo accesso da lastlogine quindi formattarlo in modo che assomigli alla versione originale. Ora puoi touch ~/.hushlogine vedrai ancora quel messaggio.


1
Ben fatto. Alla fine ci sono andato last -w | grep "$USER" | head -n1 | perl -lane 'END{print "Last login: @F[3..6] $F[8] from $F[2]"}'perché lastlogstavo troncando il mio nome host.
Xion345,

1
@ Xion345 Invece di grep per il vostro nome utente (che potrebbe arrivare qualcun altro con un nome utente più lungo che contiene il vostro), è possibile utilizzare last -w "$USER" | ...
Monty Harder

1
Potresti anche sapere se cambia / etc / motd, quindi puoi anche aggiungere: cmp / etc / motd ~ / .hushlogin.motd || cat / etc / motd && cp / etc / motd ~ / .hushlogin.motd
rrauenza

12

La tua .bash_profilechiamata lastlog -u "$USER"ti avvicina a qualcosa. L'output è simile a:

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

dove ovviamente ho redatto l'indirizzo IP.

last -w -n 1 ottiene un record simile, ma da un database diverso.

Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.