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 오히려이 (당신에게 당신이 포함 된 긴 이름을 가진 다른 사람을 얻을 수 있음) 사용자 이름에 대한 grepping, 당신이 사용할 수있는 것보다 last -w "$USER" | ...
몬티 세게

1
또한 / etc / motd가 변경되는지 알고 싶을 수도 있습니다. cmp / etc / motd ~ / .hushlogin.motd || 고양이 / etc / motd && cp / etc / motd ~ / .hushlogin.motd
rrauenza

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.