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

วิธีหนึ่งที่จะเพิ่มต่อไปนี้~/.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
@ Xion345 แทนที่จะทำเพื่อชื่อผู้ใช้ของคุณ (ซึ่งอาจทำให้คุณมีคนอื่นที่มีชื่อผู้ใช้ที่มีชื่อของคุณนานกว่า) คุณสามารถใช้ที่last -w "$USER" | ...นั่นได้
Monty Harder

1
คุณอาจต้องการทราบว่าการเปลี่ยนแปลง / etc / motd ยังสามารถเพิ่ม: cmp / etc / motd ~ / .hushlogin.motd || cat / etc / motd && cp / etc / motd ~ /
.hushlogin.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.