星空网 > 软件开发 > 操作系统

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


Linux如何找出用户的创建时间

 

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

 

Linux如何找出用户的创建时间

 

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


 

Linux如何找出用户的创建时间

 

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

 

 




原标题:Linux如何找出用户的创建时间

关键词:linux

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

一年多速卖通卖家“双11”卖出30万美金,卖家表示“非常满意”:https://www.ikjzd.com/articles/10999
印尼电商巨头Tokopedia推出穆斯林电商频道:https://www.ikjzd.com/articles/109990
虾皮选品的八大渠道:https://www.ikjzd.com/articles/109991
美国零售服务提供商b8ta获5000万美元C轮融资:https://www.ikjzd.com/articles/109992
警惕!2019年底外贸骗局大曝光!:https://www.ikjzd.com/articles/109993
亚马逊如何有效分析竞争对手Google广告数据?:https://www.ikjzd.com/articles/109994
永康白云风景区怎么走 白云山风景区怎么去??:https://www.vstour.cn/a/363181.html
2022世界杯门票如何买?:https://www.vstour.cn/a/363182.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流