{"id":195522,"date":"2020-07-21T08:19:25","date_gmt":"2020-07-21T00:19:25","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=195522"},"modified":"2020-07-15T10:35:05","modified_gmt":"2020-07-15T02:35:05","slug":"linux-user-behavior-analysis","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-user-behavior-analysis.html","title":{"rendered":"Linux\u7528\u6237\u884c\u4e3a\u5206\u6790"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5982\u679c\u60a8\u5728\u7ba1\u7406Linux\u670d\u52a1\u5668\uff0c\u6700\u597d\u51c6\u5907\u597d\u4f7f\u7528\u7528\u4e8e\u68c0\u67e5\u7528\u6237\u6d3b\u52a8\u7684\u591a\u4e2a\u547d\u4ee4\u2014\u2014\u7528\u6237\u4f55\u65f6\u767b\u5f55\u53ca\u767b\u5f55\u9891\u7387\u3001\u5c5e\u4e8e\u54ea\u4e9b\u7528\u6237\u7ec4\u3001\u8017\u7528\u591a\u5c11\u78c1\u76d8\u7a7a\u95f4\u3001\u8fd0\u884c\u4ec0\u4e48\u547d\u4ee4\u3001\u5360\u7528\u591a\u5c11\u78c1\u76d8\u7a7a\u95f4\u3001\u662f\u5426\u5728\u9605\u8bfb\u90ae\u4ef6\u7b49\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u672c\u6587\u5c0f\u7f16\u5c06\u4e3a\u5927\u5bb6\u4ecb\u7ecd\u4e86\u5728Linux\u4e0b\u6709\u53ef\u4ee5\u547d\u4ee4\u53ef\u4ee5\u5e2e\u52a9\u60a8\u4e86\u89e3\u7528\u6237\u6709\u54ea\u4e9b\u3001\u67e5\u770b\u4ed6\u4eec\u5728\u5982\u4f55\u5de5\u4f5c\u3001\u4ee5\u53ca\u5206\u6790\u7528\u6237\u7684\u8be6\u7ec6\u64cd\u63a7\u884c\u4e3a\u7b49\u3002<\/p>\n

finger\u547d\u4ee4<\/strong><\/div>\n

finger\u662f\u83b7\u53d6\u7528\u6237\u4e2a\u4eba\u8d44\u6599\u7684\u4e00\u4e2a\u4fbf\u6377\u547d\u4ee4\u3002\u5b83\u4f7f\u60a8\u53ef\u4ee5\u67e5\u770b\u8c01\u5df2\u767b\u5f55\u6216\u4e13\u6ce8\u4e8e\u5355\u4e2a\u7528\u6237\uff0c\u4ee5\u67e5\u770b\u4e0a\u4e00\u6b21\u767b\u5f55\u3001\u4ed6\u4eec\u4ece\u4f55\u5904\u767b\u5f55\u3001\u95f2\u7f6e\u65f6\u95f4\u6709\u591a\u4e45(\u81ea\u8fd0\u884c\u547d\u4ee4\u4ee5\u6765\u6709\u591a\u4e45)\u7b49\u3002\u5728\u8be5\u547d\u4ee4\u4e2d\uff0c \u6211\u4eec\u67e5\u770b\u7528\u6237nemo\u3002<\/p>\n

\r\n$ finger nemo  \r\nLogin: nemo Name: Nemo Demo  \r\nDirectory: \/home\/nemo Shell: \/bin\/bash  \r\nOn since Fri Jun 19 12:58 (EDT) on pts\/1 from 192.168.0.6  \r\n7 minutes 47 seconds idle  \r\nNew mail received Wed Jun 17 18:31 2020 (EDT)  \r\nUnread since Sat Jun 13 18:03 2020 (EDT)  \r\nNo Plan. \r\n<\/pre>\n

\u6211\u4eec\u53ef\u4ee5\u770b\u5230nemo\u7684\u5168\u540d\u3001\u4e3b\u76ee\u5f55\u548c\u5916\u58f3\uff0c\u8fd8\u53ef\u4ee5\u770b\u5230nemo\u7684\u6700\u65b0\u767b\u5f55\u548c\u7535\u5b50\u90ae\u4ef6\u6d3b\u52a8\u3002\u4ec5\u5728\/etc\/passwd\u6587\u4ef6\u4e2d\u7684\u5168\u540d\u5b57\u6bb5\u4e2d\u5b9a\u4e49\u4e86\u529e\u516c\u5ba4\u3001\u529e\u516c\u5ba4\u7535\u8bdd\u548c\u5bb6\u5ead\u7535\u8bdd\u53f7\u7801\uff0c\u8fd9\u4e9b\u4fe1\u606f\u624d\u5305\u62ec\u5728\u5185\u3002\u6bd4\u5982\u8bf4\uff1a<\/p>\n

nemo:x:1001:1001:Nemo Demo,11,540-222-2222,540-333-3333:\/home\/nemo:\/bin\/bash).<\/pre>\n

\u4e0a\u9762\u7684\u8f93\u51fa\u8fd8\u8868\u660enemo\u6ca1\u6709\u201c\u8ba1\u5212\u201d\uff0c\u4f46\u8fd9\u53ea\u662f\u610f\u5473\u7740\u8be5\u7528\u6237\u6ca1\u6709\u521b\u5efa.plan\u6587\u4ef6\u3001\u5e76\u5c06\u4e00\u4e9b\u6587\u672c\u653e\u5165\u5176\u4e2d\u3002\u8fd9\u5e76\u4e0d\u7f55\u89c1\u3002<\/p>\n

\u5982\u679c\u6ca1\u6709\u53c2\u6570\uff0cfinger\u5c06\u4ee5\u5982\u4e0b\u6240\u793a\u7684\u683c\u5f0f\u663e\u793a\u5f53\u524d\u767b\u5f55\u5217\u8868\u3002\u60a8\u53ef\u4ee5\u770b\u5230\u4ed6\u4eec\u4f55\u65f6\u767b\u5f55\u3001\u4ece\u54ea\u4e2aIP\u5730\u5740\u767b\u5f55\u3001\u4f7f\u7528\u4e2d\u7684\u4f2a\u7ec8\u7aef(\u6bd4\u5982pts\/1)\u4ee5\u53ca\u95f2\u7f6e\u4e86\u591a\u4e45\u3002<\/p>\n

\r\n$ finger  \r\nLogin Name Tty Idle Login Time Office Office Phone  \r\nnemo Nemo Demo pts\/1 1:24 Jun 19 12:58 (192.168.0.6)  \r\nshs Sandra Henry-Stocker pts\/0 Jun 19 12:57 (192.168.0.60 \r\n<\/pre>\n
w\u547d\u4ee4<\/strong><\/div>\n

w\u547d\u4ee4\u4e5f\u4ee5\u4e00\u4efd\u683c\u5f0f\u6e05\u6670\u7684\u5217\u8868\u663e\u793a\u4e86\u76ee\u524d\u6d3b\u52a8\u7684\u7528\u6237\uff0c\u5305\u62ec\u95f2\u7f6e\u65f6\u95f4\u3001\u7528\u6237\u6700\u8fd1\u8fd0\u884c\u4e86\u4ec0\u4e48\u547d\u4ee4\u3002\u5b83\u8fd8\u5728\u6700\u4e0a\u9762\u4e00\u884c\u663e\u793a\u7cfb\u7edf\u5df2\u8fd0\u884c\u4e86\u591a\u4e45\uff0c\u5e76\u63d0\u4f9b\u8d1f\u8f7d\u5e73\u5747\u6570\u5b57\uff0c\u8868\u660e\u7cfb\u7edf\u6709\u591a\u5fd9\u788c\u3002\u5728\u8fd9\u91cc\uff0c\u7cfb\u7edf\u57fa\u672c\u4e0a\u5904\u4e8e\u95f2\u7f6e\u72b6\u6001\u3002<\/p>\n

\r\n$ w  \r\n14:23:19 up 1 day, 20:24, 2 users, load average: 0.00, 0.00, 0.00  \r\nUSER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT  \r\nshs pts\/0 192.168.0.6 12:57 0.00s 0.14s 0.01s w  \r\nnemo pts\/1 192.168.0.6 12:58 1:24m 0.03s 0.03s -bash \r\n<\/pre>\n
id\u547d\u4ee4<\/strong><\/div>\n

\u5982\u679c\u4f7f\u7528id\u547d\u4ee4\uff0c\u60a8\u53ef\u4ee5\u67e5\u770b\u7528\u6237\u7684\u6570\u503cID\u548c\u7528\u6237\u7ec4ID\u4ee5\u53ca\u8be5\u7528\u6237\u662f\u54ea\u4e9b\u7528\u6237\u7ec4\u7684\u6210\u5458\u3002\u8fd9\u4e9b\u4fe1\u606f\u4ece\/etc\/passwd\u6587\u4ef6\u548c\/etc\/group\u6587\u4ef6\u83b7\u53d6\u800c\u6765\u3002\u6ca1\u6709\u53c2\u6570\u7684id\u62a5\u544a\u60a8\u5e10\u6237\u7684\u4fe1\u606f\u3002<\/p>\n

\r\n$ id  \r\nuid=1000(shs) gid=1000(shs) groups=1000(shs),4(adm),11(admin),24(cdrom),27(sudo),30(dip),46(plugdev),118(lpadmin),128(sambashare),500(devops)  \r\n$ id nemo  \r\nuid=1001(nemo) gid=1001(nemo) groups=1001(nemo),16(fish)  \r\nauth.log \r\n<\/pre>\n

\u60a8\u53ef\u4ee5\u4f7f\u7528grep\u4e4b\u7c7b\u7684\u547d\u4ee4\u4ece\/var\/log\/auth.log\u6587\u4ef6\u83b7\u53d6\u4fe1\u606f\u3002\u4e3a\u4e86\u4f7f\u7528auth.log\u6570\u636e\u663e\u793a\u6700\u8fd1\u767b\u5f55\u6d3b\u52a8\uff0c\u60a8\u53ef\u4ee5\u8fd0\u884c\u8fd9\u6837\u7684\u547d\u4ee4\uff1a<\/p>\n

\r\n$ grep \"New session\" \/var\/log\/auth.log | awk '{print $1,$2,$3,$11}' | tail -5  \r\nJun 17 17:22:38 shs.  \r\nJun 17 17:58:43 gdm.  \r\nJun 17 18:09:58 shs.  \r\nJun 19 12:57:36 shs.  \r\nJun 19 12:58:44 nemo.  \r\n<\/pre>\n
last\u547d\u4ee4<\/strong><\/div>\n

last\u547d\u4ee4\u53ef\u80fd\u6700\u64c5\u957f\u67e5\u770b\u6240\u6709\u7528\u6237\u6216\u67d0\u4e00\u4e2a\u7528\u6237\u7684\u6700\u8fd1\u767b\u5f55\u3002\u8bb0\u4f4f\u4e00\u70b9\uff1alast\u9996\u5148\u663e\u793a\u6700\u8fd1\u7684\u6d3b\u52a8\uff0c\u56e0\u4e3a\u8fd9\u662f\u5927\u591a\u6570\u7ba1\u7406\u5458\u6700\u611f\u5174\u8da3\u7684\u4fe1\u606f\u3002<\/p>\n

\r\n$ last | head -5  \r\nnemo pts\/1 192.168.0.6 Fri Jun 19 12:58 still logged in  \r\nshs pts\/0 192.168.0.6 Fri Jun 19 12:57 still logged in  \r\nshs pts\/0 192.168.0.6 Wed Jun 17 18:10 - 18:42 (00:32)  \r\nreboot system boot 5.4.0-37-generic Wed Jun 17 17:58 still running  \r\nshs pts\/2 192.168.0.6 Wed Jun 17 17:22 - 17:57 (00:34)  \r\n$ last nemo | head -5  \r\nnemo pts\/1 192.168.0.6 Fri Jun 19 12:58 - 16:21 (03:22)  \r\nnemo pts\/2 192.168.0.6 Sat Jun 13 17:49 - 19:05 (01:16)  \r\nnemo pts\/1 192.168.0.6 Thu Jun 4 17:33 - 17:44 (00:10)  \r\nnemo pts\/1 192.168.0.19 Mon May 11 19:04 - 19:57 (00:52)  \r\nnemo pts\/1 192.168.0.19 Tue May 5 12:46 - 17:49 (05:02) \r\n<\/pre>\n
du\u547d\u4ee4<\/strong><\/div>\n

\u5982\u679c\u9488\u5bf9\/home\u4e2d\u7684\u6bcf\u4e2a\u76ee\u5f55\u8fd0\u884c\uff0cdu\u547d\u4ee4\u4f1a\u62a5\u544a\u6bcf\u4e2a\u7528\u6237\u7684\u4e3b\u76ee\u5f55\u5728\u4f7f\u7528\u591a\u5c11\u7a7a\u95f4\uff0c\u5c31\u50cf\u8fd9\u6837\uff1a<\/p>\n

\r\n$ sudo du -sk \/home\/*  \r\n289 \/home\/dorothy  \r\n116 \/home\/dory  \r\n88 \/home\/eel  \r\n28 \/home\/gino  \r\n28 \/home\/jadep  \r\n12764 \/home\/nemo  \r\n732 \/home\/shark  \r\n418046 \/home\/shs  \r\n108 \/home\/tadpole \r\n<\/pre>\n

\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u62a5\u544a\u7684\u5927\u5c0f\u4ee51024\u5b57\u8282\u4e3a\u5355\u4f4d\u3002<\/p>\n

ps\u548chistory\u547d\u4ee4<\/strong><\/div>\n

\u9488\u5bf9\u5f53\u524d\u767b\u5f55\u7684\u7528\u6237\uff0c\u60a8\u59cb\u7ec8\u53ef\u4ee5\u4f7f\u7528ps -ef | grep ^nemo\u4e4b\u7c7b\u7684\u547d\u4ee4\uff0c\u67e5\u770b\u7528\u6237\u76ee\u524d\u5728\u8fd0\u884c\u54ea\u4e9b\u547d\u4ee4\u548c\u8fdb\u7a0b\u3002\u60f3\u67e5\u770b\u4ee5\u524d\u8fd0\u884c\u7684\u547d\u4ee4\uff0c\u53ef\u4ee5\u8bd5\u7740\u67e5\u770b\u7528\u6237\u7684\u5386\u53f2\u8bb0\u5f55\u6587\u4ef6(\u6bd4\u5982.bash_history)\uff0c\u4e0d\u8fc7\u8981\u6ce8\u610f\uff0c\u7528\u6237\u53ef\u4ee5\u8bbe\u7f6e\u5e10\u6237\uff0c\u4ee5\u4fbf\u67d0\u4e9b\u547d\u4ee4\u4e0d\u88ab\u6355\u83b7\u5230\u5386\u53f2\u8bb0\u5f55\u6587\u4ef6\u4e2d\uff0c\u4ed6\u4eec\u8fd8\u53ef\u4ee5\u7f16\u8f91\u8fd9\u4e9b\u6587\u4ef6\uff0c\u5982\u679c\u9009\u62e9\u8fd9\u4e48\u505a\u7684\u8bdd\u3002<\/p>\n

\u7edf\u8ba1\u767b\u5f55\u6b21\u6570<\/strong><\/div>\n

\u5982\u679c\u60a8\u60f3\u67e5\u770b\u81ea\/var\/log\/wtmp\u6587\u4ef6\u4e0a\u4e00\u6b21\u7ffb\u8f6c\u4ee5\u6765\u6bcf\u4e2a\u7528\u6237\u767b\u5f55\u7684\u6b21\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528\u8fd9\u6837\u7684\u547d\u4ee4\uff1a<\/p>\n

\r\n$ for USER in `ls \/home` \r\n> do  \r\n> cnt=`last $USER | grep ^$USER | wc -l` # count logins  \r\n> echo $USER: $cnt # show login count  \r\n> done \r\n<\/pre>\n

\u8f93\u51fa\u4f1a\u50cf\u662f\u8fd9\u6837\uff1a<\/p>\n

\r\ndorothy: 0  \r\ndory: 0  \r\neel: 8  \r\ngino: 0  \r\njadep: 102  \r\nnemo: 39  \r\nshark: 50  \r\nshs: 105  \r\ntadpole: 0\r\n<\/pre>\n

\u5982\u679c\u60a8\u60f3\u8981\u66f4\u591a\u7684\u7ec6\u8282\uff0c\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u8f83\u590d\u6742\u7684\u811a\u672c\uff0c\u4ee5\u4fbf\u6dfb\u52a0\u53e6\u5916\u4e00\u4e9b\u4fe1\u606f\uff0c\u6bd4\u5982\u767b\u5f55\u7ec6\u8282\u548c\u683c\u5f0f\u3002<\/p>\n

\r\n#!\/bin\/bash  \r\nsepline=\"====================\"  \r\nfor USER in `ls \/home`  \r\ndo  \r\nlen=`echo $USER | awk '{print length($0)}'` # get length of username  \r\necho $USER  \r\nsep=\"${sepline:1:$len}\" # set separator  \r\necho $sep # print separator  \r\ncnt=`last $USER | grep ^$USER | wc -l` # count logins  \r\necho logins: $cnt # show login count  \r\nlast $USER | grep ^$USER | head -5 # show most recent logins  \r\necho  \r\ndone \r\n<\/pre>\n

\u4e0a\u8ff0\u811a\u672c\u5c06\u663e\u793a\u7684\u6570\u636e\u9650\u5236\u5728\u6700\u8fd1\u7684\u4e94\u6b21\u767b\u5f55\uff0c\u4f46\u662f\u60a8\u53ef\u4ee5\u8f7b\u677e\u6539\u53d8\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7528\u6237\u7684\u6570\u636e\u7684\u683c\u5f0f\u4f1a\u4ec0\u4e48\u6837\uff1a<\/p>\n

\r\nshs  \r\n===  \r\nlogins: 105  \r\nshs pts\/0 192.168.0.6 Fri Jun 19 12:57 still logged in  \r\nshs pts\/0 192.168.0.6 Wed Jun 17 18:10 - 18:42 (00:32)  \r\nshs pts\/2 192.168.0.6 Wed Jun 17 17:22 - 17:57 (00:34)  \r\nshs pts\/0 192.168.0.25 Wed Jun 17 17:20 - 17:57 (00:36)  \r\nshs pts\/1 192.168.0.6 Wed Jun 17 15:19 - 17:57 (02:38) \r\n<\/pre>\n
\u68c0\u67e5\u4f01\u56fe\u4f7f\u7528sudo\u7684\u60c5\u51b5<\/strong><\/div>\n

\u5982\u679c\u60a8\u60f3\u770b\u770b\u7528\u6237\u4e2d\u6709\u8c01\u4f01\u56fe\u4f7f\u7528sudo\u3001\u800c\u4ed6\u4eec\u672c\u65e0\u8fd9\u9879\u6743\u9650\uff0c\u53ef\u4ee5\u8fd0\u884c\u8fd9\u6837\u7684\u547d\u4ee4\uff1a<\/p>\n

\r\n$ grep \"NOT in sudoers\" \/var\/log\/auth.log | awk '{print $6}' \r\nnemo \r\n<\/pre>\n

\u5982\u679c\u60a8\u5728\u65e0\u6743\u63d0\u5347\u6743\u9650\u7684\u60c5\u51b5\u4e0b\u8bd5\u56fe\u4f7f\u7528sudo\uff0c\u800c\u7cfb\u7edf\u53d1\u51fa\u8b66\u544a\u4fe1\u606f\u201c\u7528\u6237\u540d\u4e0d\u5728sudoers\u6587\u4ef6\u4e2d\u3002\u5c06\u62a5\u544a\u8be5\u4e8b\u4ef6\u201d\uff0c\u60a8\u53ef\u80fd\u4f1a\u77e5\u9053\u8fd9\u4e2a\u65e5\u5fd7\u6761\u76ee\u662f\u8be5\u62a5\u544a\u7684\u7cbe\u9ad3\u3002\u9664\u975e\u7ba1\u7406\u5458\u7aed\u529b\u5bfb\u627esudo\u4f7f\u7528\u8fdd\u89c4\uff0c\u5426\u5219\u5b83\u4eec\u4e0d\u4f1a\u88ab\u4eba\u6ce8\u610f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u672c\u6587\u5c0f\u7f16\u5c06\u4e3a\u5927\u5bb6\u4ecb\u7ecd\u4e86\u5728Linux\u4e0b\u6709\u53ef\u4ee5\u547d\u4ee4\u53ef\u4ee5\u5e2e\u52a9\u60a8\u4e86\u89e3\u7528\u6237\u6709\u54ea\u4e9b\u3001\u67e5\u770b\u4ed6\u4eec\u5728\u5982\u4f55\u5de5\u4f5c\u3001\u4ee5\u53ca\u5206\u6790\u7528\u6237\u7684\u8be6\u7ec6 […]<\/p>\n","protected":false},"author":1329,"featured_media":195525,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-195522","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/195522","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1329"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=195522"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/195522\/revisions"}],"predecessor-version":[{"id":195526,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/195522\/revisions\/195526"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/195525"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=195522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=195522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=195522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}