zoukankan      html  css  js  c++  java
  • 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 ~]# 

    clip_image001

     

    如上所示,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会循环覆盖。时间较早创建的用户根本无法从这些日志里面找到。

     

    clip_image002

     

    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 ~]# 

    clip_image003

     

    方法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

     

    如上所示,这些方法都不是标准方法,在有些场景可能会失效,那么最好的方法是在创建用户时,在系统或文档里面登记,记录这些账号的创建时间、创建原因以及用途。另外,创建账号时最好使用参数-c对其进行注释。

     

    参考资料:

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

     

     

  • 相关阅读:
    password
    bzoj 1458: 士兵占领
    国家集训队2011 happiness
    cogs 2051. 王者之剑
    uva 10779 Collectors Problem
    [Jxoi2012]奇怪的道路
    天神下凡
    藏宝图
    黑红树
    愤怒的小鸟
  • 原文地址:https://www.cnblogs.com/kerrycode/p/5603173.html
Copyright © 2011-2022 走看看