{"id":44534,"date":"2024-10-06T16:20:15","date_gmt":"2024-10-06T08:20:15","guid":{"rendered":"https:\/\/server.hk\/cnblog\/44534\/"},"modified":"2024-10-06T16:20:16","modified_gmt":"2024-10-06T08:20:16","slug":"linux-%e4%bc%ba%e6%9c%8d%e5%99%a8%e5%ae%89%e5%85%a8%e7%ad%96%e7%95%a5%e6%8a%80%e5%b7%a7%ef%bc%9a%e4%bd%bf%e7%94%a8-selinux","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/44534\/","title":{"rendered":"Linux \u4f3a\u670d\u5668\u5b89\u5168\u7b56\u7565\u6280\u5de7\uff1a\u4f7f\u7528 SELinux"},"content":{"rendered":"<h1 id=\"linux-%e4%bc%ba%e6%9c%8d%e5%99%a8%e5%ae%89%e5%85%a8%e7%ad%96%e7%95%a5%e6%8a%80%e5%b7%a7%ef%bc%9a%e4%bd%bf%e7%94%a8-selinux-ZIiiwsCKDS\">Linux \u4f3a\u670d\u5668\u5b89\u5168\u7b56\u7565\u6280\u5de7\uff1a\u4f7f\u7528 SELinux<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u4f4d\u6642\u4ee3\uff0c\u4f3a\u670d\u5668\u5b89\u5168\u6027\u6210\u70ba\u4e86\u6bcf\u500b\u4f01\u696d\u548c\u500b\u4eba\u4f7f\u7528\u8005\u7684\u9996\u8981\u8003\u91cf\u3002Linux \u4f5c\u70ba\u4e00\u500b\u958b\u6e90\u7684\u64cd\u4f5c\u7cfb\u7d71\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u4f3a\u670d\u5668\u74b0\u5883\u4e2d\uff0c\u800c SELinux\uff08Security-Enhanced Linux\uff09\u5247\u662f\u52a0\u5f37 Linux \u7cfb\u7d71\u5b89\u5168\u6027\u7684\u91cd\u8981\u5de5\u5177\u4e4b\u4e00\u3002\u672c\u6587\u5c07\u63a2\u8a0e SELinux \u7684\u57fa\u672c\u6982\u5ff5\u3001\u5de5\u4f5c\u539f\u7406\u53ca\u5176\u5728 Linux \u4f3a\u670d\u5668\u5b89\u5168\u7b56\u7565\u4e2d\u7684\u61c9\u7528\u6280\u5de7\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-selinux%ef%bc%9f-ZIiiwsCKDS\">\u4ec0\u9ebc\u662f SELinux\uff1f<\/h2>\n<p>SELinux \u662f\u7531\u7f8e\u570b\u570b\u5bb6\u5b89\u5168\u5c40\uff08NSA\uff09\u958b\u767c\u7684\u4e00\u7a2e Linux \u6838\u5fc3\u5b89\u5168\u6a21\u7d44\uff0c\u65e8\u5728\u63d0\u4f9b\u5f37\u5236\u8a2a\u554f\u63a7\u5236\uff08MAC\uff09\u529f\u80fd\u3002\u8207\u50b3\u7d71\u7684\u81ea\u9858\u8a2a\u554f\u63a7\u5236\uff08DAC\uff09\u4e0d\u540c\uff0cSELinux \u900f\u904e\u5b9a\u7fa9\u5b89\u5168\u7b56\u7565\u4f86\u9650\u5236\u7a0b\u5e8f\u548c\u7528\u6236\u7684\u884c\u70ba\uff0c\u5f9e\u800c\u63d0\u9ad8\u7cfb\u7d71\u7684\u5b89\u5168\u6027\u3002<\/p>\n<h2 id=\"selinux-%e7%9a%84%e5%b7%a5%e4%bd%9c%e5%8e%9f%e7%90%86-ZIiiwsCKDS\">SELinux \u7684\u5de5\u4f5c\u539f\u7406<\/h2>\n<p>SELinux \u7684\u6838\u5fc3\u5728\u65bc\u5176\u5b89\u5168\u4e0a\u4e0b\u6587\uff08security context\uff09\uff0c\u6bcf\u500b\u6587\u4ef6\u3001\u9032\u7a0b\u548c\u7aef\u53e3\u90fd\u6709\u4e00\u500b\u8207\u4e4b\u76f8\u95dc\u7684\u5b89\u5168\u4e0a\u4e0b\u6587\u3002\u9019\u4e9b\u4e0a\u4e0b\u6587\u7531\u4e09\u500b\u4e3b\u8981\u90e8\u5206\u7d44\u6210\uff1a<\/p>\n<ul>\n<li><strong>\u7528\u6236\uff08user\uff09<\/strong>\uff1a\u5b9a\u7fa9\u4e86\u9032\u7a0b\u7684\u64c1\u6709\u8005\u3002<\/li>\n<li><strong>\u89d2\u8272\uff08role\uff09<\/strong>\uff1a\u5b9a\u7fa9\u4e86\u7528\u6236\u5728\u7cfb\u7d71\u4e2d\u7684\u89d2\u8272\u3002<\/li>\n<li><strong>\u985e\u578b\uff08type\uff09<\/strong>\uff1a\u5b9a\u7fa9\u4e86\u5c0d\u8c61\u7684\u985e\u578b\uff0c\u9019\u662f SELinux \u4e2d\u6700\u91cd\u8981\u7684\u90e8\u5206\u3002<\/li>\n<\/ul>\n<p>\u7576\u4e00\u500b\u9032\u7a0b\u8a66\u5716\u8a2a\u554f\u67d0\u500b\u8cc7\u6e90\u6642\uff0cSELinux \u6703\u6aa2\u67e5\u8a72\u9032\u7a0b\u7684\u5b89\u5168\u4e0a\u4e0b\u6587\u8207\u8cc7\u6e90\u7684\u5b89\u5168\u4e0a\u4e0b\u6587\u662f\u5426\u7b26\u5408\u9810\u5b9a\u7684\u5b89\u5168\u7b56\u7565\u3002\u5982\u679c\u4e0d\u7b26\u5408\uff0c\u5247\u8a2a\u554f\u5c07\u88ab\u62d2\u7d55\u3002<\/p>\n<h2 id=\"%e5%a6%82%e4%bd%95%e5%95%9f%e7%94%a8%e5%92%8c%e9%85%8d%e7%bd%ae-selinux-ZIiiwsCKDS\">\u5982\u4f55\u555f\u7528\u548c\u914d\u7f6e SELinux<\/h2>\n<p>\u5728\u5927\u591a\u6578 Linux \u767c\u884c\u7248\u4e2d\uff0cSELinux \u9810\u8a2d\u662f\u555f\u7528\u7684\uff0c\u4f46\u6709\u6642\u53ef\u80fd\u9700\u8981\u624b\u52d5\u914d\u7f6e\u3002\u4ee5\u4e0b\u662f\u555f\u7528\u548c\u914d\u7f6e SELinux \u7684\u57fa\u672c\u6b65\u9a5f\uff1a<\/p>\n<pre><code>1. \u6aa2\u67e5 SELinux \u72c0\u614b\uff1a\n   sestatus\n\n2. \u5982\u679c\u9700\u8981\u555f\u7528 SELinux\uff0c\u7de8\u8f2f \/etc\/selinux\/config \u6587\u4ef6\uff1a\n   SELINUX=enforcing\n\n3. \u91cd\u65b0\u555f\u52d5\u7cfb\u7d71\u4ee5\u4f7f\u66f4\u6539\u751f\u6548\u3002<\/code><\/pre>\n<h2 id=\"selinux-%e7%ad%96%e7%95%a5%e7%ae%a1%e7%90%86-ZIiiwsCKDS\">SELinux \u7b56\u7565\u7ba1\u7406<\/h2>\n<p>SELinux \u4f7f\u7528\u7b56\u7565\u4f86\u5b9a\u7fa9\u54ea\u4e9b\u64cd\u4f5c\u662f\u88ab\u5141\u8a31\u7684\u3002\u9019\u4e9b\u7b56\u7565\u53ef\u4ee5\u662f\u9810\u8a2d\u7684\uff0c\u4e5f\u53ef\u4ee5\u662f\u81ea\u5b9a\u7fa9\u7684\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u7684 SELinux \u7b56\u7565\u7ba1\u7406\u547d\u4ee4\uff1a<\/p>\n<ul>\n<li><code>getsebool<\/code>\uff1a\u6aa2\u67e5\u5e03\u723e\u503c\u7684\u7576\u524d\u72c0\u614b\u3002<\/li>\n<li><code>setsebool<\/code>\uff1a\u8a2d\u7f6e\u5e03\u723e\u503c\u4ee5\u6539\u8b8a\u7b56\u7565\u884c\u70ba\u3002<\/li>\n<li><code>semanage<\/code>\uff1a\u7ba1\u7406 SELinux \u7b56\u7565\u7684\u5de5\u5177\u3002<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff0c\u82e5\u8981\u5141\u8a31 HTTPD \u670d\u52d9\u8a2a\u554f\u7db2\u7d61\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>setsebool -P httpd_can_network_connect on<\/code><\/pre>\n<h2 id=\"selinux-%e7%9a%84%e6%97%a5%e8%aa%8c%e5%92%8c%e6%95%85%e9%9a%9c%e6%8e%92%e9%99%a4-ZIiiwsCKDS\">SELinux \u7684\u65e5\u8a8c\u548c\u6545\u969c\u6392\u9664<\/h2>\n<p>\u7576 SELinux \u963b\u6b62\u67d0\u500b\u64cd\u4f5c\u6642\uff0c\u6703\u5728\u7cfb\u7d71\u65e5\u8a8c\u4e2d\u8a18\u9304\u76f8\u95dc\u4fe1\u606f\u3002\u9019\u4e9b\u65e5\u8a8c\u901a\u5e38\u4f4d\u65bc <code>\/var\/log\/audit\/audit.log<\/code>\u3002\u4f7f\u7528 <code>ausearch<\/code> \u547d\u4ee4\u53ef\u4ee5\u8f15\u9b06\u67e5\u627e\u9019\u4e9b\u65e5\u8a8c\u689d\u76ee\uff1a<\/p>\n<pre><code>ausearch -m avc -ts recent<\/code><\/pre>\n<p>\u9019\u5c07\u986f\u793a\u6700\u8fd1\u7684 SELinux \u62d2\u7d55\u4e8b\u4ef6\uff0c\u5e6b\u52a9\u7ba1\u7406\u54e1\u5feb\u901f\u5b9a\u4f4d\u554f\u984c\u3002<\/p>\n<h2 id=\"%e7%b5%90%e8%ab%96-ZIiiwsCKDS\">\u7d50\u8ad6<\/h2>\n<p>SELinux \u662f\u4e00\u500b\u5f37\u5927\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u986f\u8457\u63d0\u9ad8 Linux \u4f3a\u670d\u5668\u7684\u5b89\u5168\u6027\u3002\u901a\u904e\u6b63\u78ba\u7684\u914d\u7f6e\u548c\u7ba1\u7406\uff0c\u60a8\u53ef\u4ee5\u6709\u6548\u5730\u9632\u6b62\u672a\u7d93\u6388\u6b0a\u7684\u8a2a\u554f\u548c\u6f5b\u5728\u7684\u5b89\u5168\u5a01\u8105\u3002\u7121\u8ad6\u60a8\u662f\u7ba1\u7406\u4f01\u696d\u4f3a\u670d\u5668\u9084\u662f\u500b\u4eba\u9805\u76ee\uff0c\u4e86\u89e3\u548c\u4f7f\u7528 SELinux \u90fd\u662f\u78ba\u4fdd\u7cfb\u7d71\u5b89\u5168\u7684\u91cd\u8981\u6b65\u9a5f\u3002<\/p>\n<p>\u5982\u9700\u9032\u4e00\u6b65\u4e86\u89e3\u5982\u4f55\u4fdd\u8b77\u60a8\u7684\u4f3a\u670d\u5668\uff0c\u8acb\u53c3\u8003\u6211\u5011\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0c\u7372\u53d6\u66f4\u591a\u8cc7\u8a0a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22 Linux \u4f3a\u670d\u5668\u5b89\u5168\u7b56\u7565\u6280\u5de7\uff0c\u5b78\u7fd2\u5982\u4f55\u6709\u6548\u4f7f\u7528 SELinux \u4f86\u52a0\u5f37\u7cfb\u7d71\u5b89\u5168\u6027\u8207\u9632\u8b77\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-44534","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/44534","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=44534"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/44534\/revisions"}],"predecessor-version":[{"id":44535,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/44534\/revisions\/44535"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=44534"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=44534"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=44534"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}