Bash .hushlogin、最終ログイン時刻とホストを保持


19

私の会社では、いくつかのサーバーにログインすると、最後のログインと大きなバナーが表示されます。

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$ 

もちろん、ログインするたびにこの巨大なバナーが表示されるのは望ましくありませんが、最後のログイン時刻とホストは表示したままにしおきたいと思います

使用する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$

回答:


15

1つの方法は~/.ssh/rc、マシンにsshするときに実行されるコマンドを含む次のものをに追加することです。

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

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


1
良いですね。ホスト名を切り捨てていたlast -w | grep "$USER" | head -n1 | perl -lane 'END{print "Last login: @F[3..6] $F[8] from $F[2]"}'ので、ついに行きましたlastlog
Xion345

1
(あなたはあなたが含まれている長いユーザ名を持つ他の誰かを取得する可能性があります)ユーザー名のためにgrepをよりXion345むしろ@は、使用することができますlast -w "$USER" | ...
モンティ・ハーダー

1
また、/ etc / motdが変更されたかどうかを知りたい場合もあります。追加するには、cmp / etc / motd〜/ .hushlogin.motd || 猫/ etc / motd && cp / etc /
motd〜

12

あなたの持って.bash_profile通話することはlastlog -u "$USER"非常に近い何かを取得します。出力は次のようになります。

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

もちろん、私はIPアドレスを編集しました。

last -w -n 1 同様のレコードを取得しますが、異なるデータベースから取得します。

弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.