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

이를 수행하는 한 가지 방법은 ~/.ssh/rc머신에 SSH로 접속할 때 실행하려는 명령이 포함된 다음을 추가하는 것입니다.

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

이 명령은 마지막으로 로그인한 시간을 가져온 lastlogin다음 원래 버전처럼 보이도록 형식을 지정합니다. 이제 touch ~/.hushlogin메시지가 계속 표시됩니다.

답변2

.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유사한 레코드를 가져오지만 다른 데이터베이스에서 가져옵니다.

답변3

이것올바른 방법당신이 해야 할 일은 이것이다:

파일 편집:/etc/pam.d/login 그리고/etc/pam.d/sshd 그리고 다음 줄에 주석을 달아주세요:

# Prints the message of the day upon successful login.
# (Replaces the `MOTD_FILE' option in login.defs)
# This includes a dynamically generated part from /run/motd.dynamic
# and a static (admin-editable) part from /etc/motd.
#session    optional   pam_motd.so motd=/run/motd.dynamic
#session    optional   pam_motd.so noupdate

삭제하고.hushlogin또는/etc/hus로그인"만지면" 됩니다.

그게 다야.

결과:

zibris login: zibri
Password: 
Last login: Sun Jul 25 04:41:40 EET 2021 on pts/2
zibri@zibris:~$ 

건배 :D

답변4

아마도 Unix 시스템에서는 그렇지 않을 것입니다 lastlog. 그래서 @terdon과 @Xion345의 아이디어를 하나로 결합해야 했습니다.

Solaris 8-10 및 OpenBSD 4.8에서는 이것으로 충분합니다:

$ last $USER | perl -lane '!/still logged in/ && print "Last login: @F[3..6] from $F[2]" and last'
Last login: Fri Apr 24 08:36 from xxxxxxxxxx.omnit

초와 연도가 누락되었습니다( last제공되지 않았기 때문에).

-R그러나 HP-UX의 경우 호스트 이름 부분을 가져와야 합니다 .

$ last -R $USER | perl -lane '...'
Last login: Fri Apr 24 23:58 from 10.xxx.yyy.82

그러나 전체 호스트 이름을 얻고 싶으면 + Solaris를 사용하고 있다면 추가할 수 있습니다 -a. 이렇게 하면 형식이 약간 혼란스러워집니다.

$ last -a $USER | perl -lane '!/still logged in/ && print "Last login: @F[2..5] from $F[$#F]" and last'
Last login: Fri Apr 24 08:36 from xxxxxxxxxx.omnitel.lan

OpenBSD에서는 복구 초를 사용할 수 있습니다 -T. 기본적으로 호스트 이름 부분은 훨씬 더 넓습니다.

그러나 일부 시스템에서는 반대의 의미를 가질 수 있으므로 모든 옵션을 연속해서 시도하기는 쉽지 않습니다. 예를 들어. 리눅스:

       -R     Suppresses the display of the hostname field.

...HP-UX와 비교:

           -R        When used with last and lastb, -R displays the user's
                     host name as it is stored in the files /var/adm/wtmps
                     and /var/adm/btmps, respectively.  The host name is
                     displayed between the tty name and the user's login
                     time.

IOW, unices에서 이것을 스크립팅하는 쉬운 크로스 플랫폼 방법은 없습니다.

관련 정보