Linux如何找出使用者的建立時間,linux找出建立時間

來源:互聯網
上載者:User

Linux如何找出使用者的建立時間,linux找出建立時間

在Linux系統中,如何找到使用者建立的時間呢? 其實是沒有標準方法尋找使用者建立時間。下面再搜尋了一些資料後,自己驗證並測試了一下這些方法,僅供參考:

 

1:如果建立的使用者有家目錄,那麼可以ls -l /home/<username>/.bash_logout 來找到使用者的建立時間。

[root@DB-Server ~]# cat /etc/shadow | grep test
test:$1$WL5jXsvt$bJqebY44KjmhaLjaFkB1f/:16972:0:99999:7:::
[root@DB-Server ~]# cat /etc/passwd | grep test
test:x:501:501::/home/test:/bin/bash
[root@DB-Server ~]# ls -l /home/test/.bash_logout
-rw-r--r-- 1 test test 33 Jun 19 23:39 /home/test/.bash_logout
[root@DB-Server ~]# 

 

如上所示,test使用者於6月19號 23:39建立。這種方法對於沒有家目錄的使用者,顯然無法擷取其建立時間。

 

2:如果建立的使用者有家目錄,那麼可以用ls -ld /home/username/

[root@DB-Server ~]# ls -ld /home/test
drwx------ 3 test test 4096 Jun 19 23:39 /home/test

 

 

3:查看/var/log/secure相關日誌,查看使用者的建立時間

如下所示,可以看到使用者test的建立時間為2016-06-19 23:39。但是這個方法只能對最近建立的使用者才有效,因為/var/log/secure會迴圈覆蓋。時間較早建立的使用者根本無法從這些日誌裡面找到。

 

 

4:在/etc/shadow檔案裡面,第三個欄位標識表示密碼修改日期:這個是表明上一次修改密碼的日期與1970-1-1相距的天數。如果賬戶自建立後,沒有修改過密碼,就可以使用這個欄位來尋找帳號建立日期。

[root@DB-Server ~]#  awk -F ":" '{print $1, $3}'  /etc/shadow | grep kerry
kerry 16439
[root@DB-Server ~]# ls -l /home/kerry/.bash_logout
-rw-r--r-- 1 kerry kerry 33 Jan  4  2015 /home/kerry/.bash_logout
[root@DB-Server ~]# date -d "1970-01-01 16439 days" "+%Y/%m/%d %H:%M:%S" 
2015/01/04 00:00:00
[root@DB-Server ~]# passwd kerry
Changing password for user kerry.
New UNIX password: 
BAD PASSWORD: it is too simplistic/systematic
Retype new UNIX password: 
passwd: all authentication tokens updated successfully.
[root@DB-Server ~]#  awk -F ":" '{print $1, $3}'  /etc/shadow | grep kerry
kerry 16972
You have new mail in /var/spool/mail/root
[root@DB-Server ~]# date -d "1970-01-01 16972 days" "+%Y/%m/%d %H:%M:%S" 
2016/06/20 00:00:00
[root@DB-Server ~]# 

 

 

方法5:使用aureport命令查看。但是這個命令,對於有些帳號也不能查到相當相關資訊。

[root@DB-Server ~]# aureport -au | grep test
69. 01/18/2016 23:25:42 test ? pts/1 /bin/su yes 99
70. 01/18/2016 23:26:22 test 192.168.42.1 ssh /usr/sbin/sshd yes 107
71. 01/18/2016 23:26:22 test 192.168.42.1 ssh /usr/sbin/sshd no 108

 

 

參考資料:

http://linux.ittoolbox.com/groups/technical-functional/linuxadmin-l/how-to-find-out-when-a-user-is-created-in-linux-4677886#M4678008

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.