{"id":17547,"date":"2024-11-18T08:14:00","date_gmt":"2024-11-18T00:14:00","guid":{"rendered":"https:\/\/fwq.ai\/blog\/17547\/"},"modified":"2024-11-18T08:14:00","modified_gmt":"2024-11-18T00:14:00","slug":"%e7%a0%94%e7%a9%b6linux%e6%97%a5%e5%bf%97%e6%96%87%e4%bb%b6%e4%b8%ad%e5%90%84%e5%ad%97%e6%ae%b5%e7%9a%84%e5%86%85%e5%ae%b9","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/17547\/","title":{"rendered":"\u7814\u7a76Linux\u65e5\u5fd7\u6587\u4ef6\u4e2d\u5404\u5b57\u6bb5\u7684\u5185\u5bb9"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/887\/227\/170899290974753.jpg\" class=\"aligncenter\" title=\"\u7814\u7a76Linux\u65e5\u5fd7\u6587\u4ef6\u4e2d\u5404\u5b57\u6bb5\u7684\u5185\u5bb9\u63d2\u56fe\" alt=\"\u7814\u7a76Linux\u65e5\u5fd7\u6587\u4ef6\u4e2d\u5404\u5b57\u6bb5\u7684\u5185\u5bb9\u63d2\u56fe\" \/><\/p>\n<p>Linux\u4f5c\u4e3a\u4e00\u79cd\u5e7f\u6cdb\u4f7f\u7528\u7684\u64cd\u4f5c\u7cfb\u7edf\uff0c\u5177\u6709\u5f3a\u5927\u7684\u65e5\u5fd7\u7cfb\u7edf\u6765\u8bb0\u5f55\u7cfb\u7edf\u8fd0\u884c\u4e2d\u7684\u91cd\u8981\u4fe1\u606f\u3002\u65e5\u5fd7\u6587\u4ef6\u901a\u5e38\u5b58\u50a8\u5728\/var\/log\u76ee\u5f55\u4e0b\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u5404\u79cd\u4e0d\u540c\u7c7b\u578b\u7684\u65e5\u5fd7\u6587\u4ef6\uff0c\u5982\u7cfb\u7edf\u65e5\u5fd7\u3001\u5b89\u5168\u65e5\u5fd7\u7b49\u3002\u672c\u6587\u5c06\u6df1\u5165\u63a2\u8ba8Linux\u65e5\u5fd7\u6587\u4ef6\u4e2d\u7684\u5404\u5217\u5185\u5bb9\uff0c\u5e76\u7ed3\u5408\u5177\u4f53\u7684\u4ee3\u7801\u793a\u4f8b\u6765\u89e3\u91ca\u5404\u5217\u7684\u542b\u4e49\u3002<\/p>\n<h3>1. syslog\u65e5\u5fd7\u6587\u4ef6<\/h3>\n<p>syslog\u662fLinux\u4e2d\u6700\u5e38\u89c1\u7684\u65e5\u5fd7\u7cfb\u7edf\u4e4b\u4e00\uff0c\u8bb0\u5f55\u4e86\u7cfb\u7edf\u7684\u5404\u79cd\u8fd0\u884c\u4fe1\u606f\u3002syslog\u65e5\u5fd7\u6587\u4ef6\u901a\u5e38\u5b58\u50a8\u5728\/var\/log\u76ee\u5f55\u4e0b\uff0c\u5176\u4e2d\u6700\u5e38\u89c1\u7684\u662fsyslog\u6587\u4ef6\u3002\u4e0b\u9762\u662f\u4e00\u4e2asyslog\u65e5\u5fd7\u6587\u4ef6\u7684\u793a\u4f8b\u5185\u5bb9\uff1a<\/p>\n<pre>Mar 10 08:30:45 localhost cron[1234]: (root) CMD (run-parts \/etc\/cron.daily)\nMar 10 10:15:20 localhost sshd[5678]: Failed password for user1 from 192.168.1.100 port 22\nMar 11 14:55:30 localhost kernel: Out of memory: Kill process 4321 (apache2) score 500 or sacrifice child<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c\u6bcf\u884c\u65e5\u5fd7\u5185\u5bb9\u901a\u5e38\u5305\u542b\u4e86\u4ee5\u4e0b\u51e0\u5217\uff1a<\/p>\n<ul>\n<li>\u65e5\u671f\u548c\u65f6\u95f4\uff1a\u8bb0\u5f55\u4e86\u65e5\u5fd7\u4e8b\u4ef6\u53d1\u751f\u7684\u5177\u4f53\u65f6\u95f4\uff0c\u683c\u5f0f\u4e3a\u6708\u65e5 \u65f6:\u5206:\u79d2\u3002<\/li>\n<li>\u4e3b\u673a\u540d\uff1a\u6807\u8bc6\u4e86\u65e5\u5fd7\u4e8b\u4ef6\u6240\u5728\u7684\u4e3b\u673a\u540d\uff0c\u901a\u5e38\u4e3alocalhost\u3002<\/li>\n<li>\u5e94\u7528\u7a0b\u5e8f\u540d\uff1a\u6307\u793a\u4e86\u751f\u6210\u65e5\u5fd7\u7684\u5e94\u7528\u7a0b\u5e8f\u540d\u79f0\uff0c\u5982cron\u3001sshd\u3001kernel\u7b49\u3002<\/li>\n<li>\u8fdb\u7a0bID\uff1a\u8bb0\u5f55\u4e86\u751f\u6210\u65e5\u5fd7\u7684\u5e94\u7528\u7a0b\u5e8f\u5bf9\u5e94\u7684\u8fdb\u7a0bID\u3002<\/li>\n<li>\u65e5\u5fd7\u5185\u5bb9\uff1a\u5177\u4f53\u7684\u65e5\u5fd7\u4fe1\u606f\uff0c\u5982\u5931\u8d25\u767b\u5f55\u5c1d\u8bd5\u3001\u5185\u5b58\u4e0d\u8db3\u7b49\u3002<\/li>\n<\/ul>\n<h3>2. auth.log\u65e5\u5fd7\u6587\u4ef6<\/h3>\n<p>auth.log\u65e5\u5fd7\u6587\u4ef6\u8bb0\u5f55\u4e86\u7cfb\u7edf\u7684\u8eab\u4efd\u9a8c\u8bc1\u548c\u6388\u6743\u4fe1\u606f\uff0c\u53ef\u7528\u4e8e\u8ffd\u8e2a\u7528\u6237\u767b\u5f55\u548c\u6743\u9650\u66f4\u6539\u7b49\u64cd\u4f5c\u3002\u4e0b\u9762\u662f\u4e00\u4e2aauth.log\u65e5\u5fd7\u6587\u4ef6\u7684\u793a\u4f8b\u5185\u5bb9\uff1a<\/p>\n<pre>Mar 10 08:30:45 localhost sshd[1234]: Accepted publickey for user2 from 192.168.1.101 port 22\nMar 10 10:15:20 localhost sudo: user1 : TTY=pts\/0 ; PWD=\/home\/user1 ; USER=root ; COMMAND=\/bin\/bash\nMar 11 14:55:30 localhost su: pam_unix(su:session): session opened for user2 by user1(uid=0)<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728auth.log\u65e5\u5fd7\u6587\u4ef6\u4e2d\uff0c\u6bcf\u884c\u65e5\u5fd7\u5185\u5bb9\u901a\u5e38\u5305\u542b\u4e86\u4ee5\u4e0b\u51e0\u5217\uff1a<\/p>\n<ul>\n<li>\u65e5\u671f\u548c\u65f6\u95f4\uff1a\u8bb0\u5f55\u4e86\u65e5\u5fd7\u4e8b\u4ef6\u53d1\u751f\u7684\u5177\u4f53\u65f6\u95f4\u3002<\/li>\n<li>\u4e3b\u673a\u540d\uff1a\u6807\u8bc6\u4e86\u65e5\u5fd7\u4e8b\u4ef6\u6240\u5728\u7684\u4e3b\u673a\u540d\u3002<\/li>\n<li>\u5e94\u7528\u7a0b\u5e8f\u540d\uff1a\u6307\u793a\u4e86\u751f\u6210\u65e5\u5fd7\u7684\u5e94\u7528\u7a0b\u5e8f\u540d\u79f0\uff0c\u5982sshd\u3001sudo\u3001su\u7b49\u3002<\/li>\n<li>\u8fdb\u7a0bID\uff1a\u8bb0\u5f55\u4e86\u751f\u6210\u65e5\u5fd7\u7684\u5e94\u7528\u7a0b\u5e8f\u5bf9\u5e94\u7684\u8fdb\u7a0bID\u3002<\/li>\n<li>\u65e5\u5fd7\u5185\u5bb9\uff1a\u5177\u4f53\u7684\u8eab\u4efd\u9a8c\u8bc1\u548c\u6388\u6743\u4fe1\u606f\uff0c\u5982\u516c\u94a5\u767b\u5f55\u3001\u4f7f\u7528sudo\u5207\u6362\u7528\u6237\u7b49\u3002<\/li>\n<\/ul>\n<h3>3. Kernel\u65e5\u5fd7\u6587\u4ef6<\/h3>\n<p>Kernel\u65e5\u5fd7\u6587\u4ef6\u8bb0\u5f55\u4e86Linux\u5185\u6838\u7684\u8fd0\u884c\u4fe1\u606f\uff0c\u53ef\u7528\u4e8e\u8bca\u65ad\u7cfb\u7edf\u7684\u786c\u4ef6\u548c\u8f6f\u4ef6\u95ee\u9898\u3002\u4e00\u822c\u6765\u8bf4\uff0cKernel\u65e5\u5fd7\u6587\u4ef6\u7684\u8def\u5f84\u4e3a\/var\/log\/kern.log\u3002\u4e0b\u9762\u662f\u4e00\u4e2aKernel\u65e5\u5fd7\u6587\u4ef6\u7684\u793a\u4f8b\u5185\u5bb9\uff1a<\/p>\n<pre>Mar 10 08:30:45 localhost kernel: [ 123.456789] eth0: link up (1000Mbps\/Full duplex)\nMar 10 10:15:20 localhost kernel: [ 234.567890] CPU0: Core temperature above threshold, cpu clock throttled (total events = 1)\nMar 11 14:55:30 localhost kernel: [ 345.678901] Out of memory: Kill process 4321 (apache2) score 500 or sacrifice child<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728Kernel\u65e5\u5fd7\u6587\u4ef6\u4e2d\uff0c\u6bcf\u884c\u65e5\u5fd7\u5185\u5bb9\u901a\u5e38\u5305\u542b\u4e86\u4ee5\u4e0b\u51e0\u5217\uff1a<\/p>\n<ul>\n<li>\u65e5\u671f\u548c\u65f6\u95f4\uff1a\u8bb0\u5f55\u4e86\u65e5\u5fd7\u4e8b\u4ef6\u53d1\u751f\u7684\u5177\u4f53\u65f6\u95f4\u3002<\/li>\n<li>\u4e3b\u673a\u540d\uff1a\u6807\u8bc6\u4e86\u65e5\u5fd7\u4e8b\u4ef6\u6240\u5728\u7684\u4e3b\u673a\u540d\u3002<\/li>\n<li>\u5185\u6838\u6d88\u606f\uff1a\u5185\u6838\u8bb0\u5f55\u7684\u5177\u4f53\u4fe1\u606f\uff0c\u5982\u7f51\u5361\u72b6\u6001\u3001\u6e29\u5ea6\u544a\u8b66\u3001\u5185\u5b58\u4e0d\u8db3\u7b49\u3002<\/li>\n<\/ul>\n<h3>4. \u5b9e\u9645\u64cd\u4f5c\u793a\u4f8b<\/h3>\n<p>\u4e0b\u9762\u7ed9\u51fa\u4e00\u4e2a\u901a\u8fc7grep\u547d\u4ee4\u7b5b\u9009auth.log\u4e2d\u7279\u5b9a\u65e5\u5fd7\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<pre>grep \"Accepted publickey\" \/var\/log\/auth.log<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u793a\u4f8b\u5c06\u8f93\u51faauth.log\u4e2d\u5305\u542b&#8221;Accepted publickey&#8221;\u7684\u65e5\u5fd7\u5185\u5bb9\uff0c\u65b9\u4fbf\u7528\u6237\u67e5\u770b\u5177\u4f53\u7684\u516c\u94a5\u767b\u5f55\u4fe1\u606f\u3002<\/p>\n<p>\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\u548c\u793a\u4f8b\u4ee3\u7801\uff0c\u8bfb\u8005\u53ef\u4ee5\u66f4\u52a0\u6df1\u5165\u5730\u7406\u89e3Linux\u65e5\u5fd7\u6587\u4ef6\u4e2d\u5404\u5217\u5185\u5bb9\u7684\u542b\u4e49\uff0c\u4ee5\u53ca\u5982\u4f55\u901a\u8fc7\u547d\u4ee4\u884c\u5de5\u5177\u5bf9\u65e5\u5fd7\u6587\u4ef6\u8fdb\u884c\u5904\u7406\u548c\u7b5b\u9009\u3002\u7cfb\u7edf\u7ba1\u7406\u5458\u53ef\u4ee5\u5229\u7528\u8fd9\u4e9b\u4fe1\u606f\u6765\u76d1\u63a7\u7cfb\u7edf\u8fd0\u884c\u72b6\u6001\uff0c\u53ca\u65f6\u53d1\u73b0\u548c\u89e3\u51b3\u95ee\u9898\uff0c\u4fdd\u969c\u7cfb\u7edf\u7684\u7a33\u5b9a\u6027\u548c\u5b89\u5168\u6027\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u7814\u7a76Linux\u65e5\u5fd7\u6587\u4ef6\u4e2d\u5404\u5b57\u6bb5\u7684\u5185\u5bb9\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Linux\u4f5c\u4e3a\u4e00\u79cd\u5e7f\u6cdb\u4f7f\u7528\u7684\u64cd\u4f5c\u7cfb\u7edf\uff0c\u5177\u6709\u5f3a\u5927\u7684\u65e5\u5fd7\u7cfb\u7edf\u6765\u8bb0\u5f55\u7cfb\u7edf\u8fd0\u884c\u4e2d\u7684\u91cd\u8981\u4fe1\u606f\u3002\u65e5\u5fd7\u6587\u4ef6\u901a\u5e38\u5b58\u50a8\u5728\/var\/log\u76ee\u5f55\u4e0b\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u5404\u79cd\u4e0d\u540c\u7c7b\u578b\u7684\u65e5\u5fd7\u6587\u4ef6\uff0c\u5982\u7cfb\u7edf\u65e5\u5fd7\u3001\u5b89\u5168\u65e5\u5fd7\u7b49\u3002\u672c\u6587\u5c06\u6df1\u5165\u63a2\u8ba8Linux\u65e5\u5fd7\u6587\u4ef6\u4e2d\u7684\u5404\u5217\u5185\u5bb9\uff0c\u5e76\u7ed3\u5408\u5177\u4f53\u7684\u4ee3\u7801\u793a\u4f8b\u6765\u89e3\u91ca\u5404\u5217\u7684\u542b\u4e49\u3002 1. syslog\u65e5\u5fd7\u6587\u4ef6 syslog\u662fLinux\u4e2d\u6700\u5e38\u89c1\u7684\u65e5\u5fd7\u7cfb\u7edf\u4e4b\u4e00\uff0c\u8bb0\u5f55\u4e86\u7cfb\u7edf\u7684\u5404\u79cd\u8fd0\u884c\u4fe1\u606f\u3002syslog\u65e5\u5fd7\u6587\u4ef6\u901a\u5e38\u5b58\u50a8\u5728\/var\/log\u76ee\u5f55\u4e0b\uff0c\u5176\u4e2d\u6700\u5e38\u89c1\u7684\u662fsyslog\u6587\u4ef6\u3002\u4e0b\u9762\u662f\u4e00\u4e2asyslog\u65e5\u5fd7\u6587\u4ef6\u7684\u793a\u4f8b\u5185\u5bb9\uff1a Mar 10 08:30:45 localhost cron[1234]: (root) CMD (run-parts \/etc\/cron.daily) Mar 10 10:15:20 localhost sshd[5678]: Failed password for user1 from 192.168.1.100 port 22 Mar 11 14:55:30 localhost kernel: Out of memory: Kill process 4321 (apache2) score 500 or sacrifice child \u767b\u5f55\u540e\u590d\u5236 \u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c\u6bcf\u884c\u65e5\u5fd7\u5185\u5bb9\u901a\u5e38\u5305\u542b\u4e86\u4ee5\u4e0b\u51e0\u5217\uff1a \u65e5\u671f\u548c\u65f6\u95f4\uff1a\u8bb0\u5f55\u4e86\u65e5\u5fd7\u4e8b\u4ef6\u53d1\u751f\u7684\u5177\u4f53\u65f6\u95f4\uff0c\u683c\u5f0f\u4e3a\u6708\u65e5 \u65f6:\u5206:\u79d2\u3002 \u4e3b\u673a\u540d\uff1a\u6807\u8bc6\u4e86\u65e5\u5fd7\u4e8b\u4ef6\u6240\u5728\u7684\u4e3b\u673a\u540d\uff0c\u901a\u5e38\u4e3alocalhost\u3002 \u5e94\u7528\u7a0b\u5e8f\u540d\uff1a\u6307\u793a\u4e86\u751f\u6210\u65e5\u5fd7\u7684\u5e94\u7528\u7a0b\u5e8f\u540d\u79f0\uff0c\u5982cron\u3001sshd\u3001kernel\u7b49\u3002 \u8fdb\u7a0bID\uff1a\u8bb0\u5f55\u4e86\u751f\u6210\u65e5\u5fd7\u7684\u5e94\u7528\u7a0b\u5e8f\u5bf9\u5e94\u7684\u8fdb\u7a0bID\u3002 \u65e5\u5fd7\u5185\u5bb9\uff1a\u5177\u4f53\u7684\u65e5\u5fd7\u4fe1\u606f\uff0c\u5982\u5931\u8d25\u767b\u5f55\u5c1d\u8bd5\u3001\u5185\u5b58\u4e0d\u8db3\u7b49\u3002 2. auth.log\u65e5\u5fd7\u6587\u4ef6 auth.log\u65e5\u5fd7\u6587\u4ef6\u8bb0\u5f55\u4e86\u7cfb\u7edf\u7684\u8eab\u4efd\u9a8c\u8bc1\u548c\u6388\u6743\u4fe1\u606f\uff0c\u53ef\u7528\u4e8e\u8ffd\u8e2a\u7528\u6237\u767b\u5f55\u548c\u6743\u9650\u66f4\u6539\u7b49\u64cd\u4f5c\u3002\u4e0b\u9762\u662f\u4e00\u4e2aauth.log\u65e5\u5fd7\u6587\u4ef6\u7684\u793a\u4f8b\u5185\u5bb9\uff1a Mar [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-17547","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/17547","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=17547"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/17547\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=17547"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=17547"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=17547"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}