Bash .hushlogin、最後のログイン時間とホストを維持する

Bash .hushlogin、最後のログイン時間とホストを維持する

当社では、特定のサーバーにログインすると、最後のログイン情報と大きなバナーが表示されます。

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                 *
*                  [email protected]                                   *
************************************************************************
me@the-server$ 

もちろんログインするたびにこんなに巨大なバナーが現れるのは嫌だが、最後のログイン時間とホストの表示を維持する

touch ~/.hushloginバナーがないときに使うと負けると思います。最後のログイン情報。実際には何も表示されません。

ssh the-server
me@the-server$

バナーを削除し、最後のログイン時間とホストを次のように維持する方法:

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

ベストアンサー1

これを行う1つの方法は、~/.ssh/rcマシンにSSHで接続するときに実行したいコマンドを含む以下を追加することです。

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

このコマンドは、最後にログインした時刻を取得し、元のバージョンのlastloginように見えるようにフォーマットします。これでtouch ~/.hushloginメッセージが表示され続けます。

おすすめ記事