{"id":45278,"date":"2024-10-06T21:44:14","date_gmt":"2024-10-06T13:44:14","guid":{"rendered":"https:\/\/server.hk\/cnblog\/45278\/"},"modified":"2024-10-06T21:44:14","modified_gmt":"2024-10-06T13:44:14","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-centos-7-5-%e4%b8%8a%e6%9f%a5%e7%9c%8b%e3%80%81%e7%a6%81%e7%94%a8-selinux","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/45278\/","title":{"rendered":"\u5982\u4f55\u5728 CentOS 7.5 \u4e0a\u67e5\u770b\u3001\u7981\u7528 SELinux"},"content":{"rendered":"<h1 id=\"%e5%a6%82%e4%bd%95%e5%9c%a8-centos-7-5-%e4%b8%8a%e6%9f%a5%e7%9c%8b%e3%80%81%e7%a6%81%e7%94%a8-selinux-wyPNIhkvDo\">\u5982\u4f55\u5728 CentOS 7.5 \u4e0a\u67e5\u770b\u3001\u7981\u7528 SELinux<\/h1>\n<p>\u5728 CentOS 7.5 \u4e2d\uff0cSELinux\uff08Security-Enhanced Linux\uff09\u662f\u4e00\u7a2e\u5f37\u5927\u7684\u5b89\u5168\u529f\u80fd\uff0c\u65e8\u5728\u52a0\u5f37\u7cfb\u7d71\u7684\u5b89\u5168\u6027\u3002\u96d6\u7136\u5b83\u63d0\u4f9b\u4e86\u984d\u5916\u7684\u5b89\u5168\u5c64\uff0c\u4f46\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\uff0c\u7279\u5225\u662f\u5728\u958b\u767c\u6216\u6e2c\u8a66\u74b0\u5883\u4e2d\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u67e5\u770b\u6216\u7981\u7528 SELinux\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728 CentOS 7.5 \u4e0a\u67e5\u770b\u548c\u7981\u7528 SELinux\u3002<\/p>\n<h2 id=\"%e6%9f%a5%e7%9c%8b-selinux-%e7%8b%80%e6%85%8b-wyPNIhkvDo\">\u67e5\u770b SELinux \u72c0\u614b<\/h2>\n<p>\u8981\u67e5\u770b SELinux \u7684\u7576\u524d\u72c0\u614b\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>getenforce<\/code><\/pre>\n<p>\u9019\u500b\u547d\u4ee4\u6703\u8fd4\u56de\u4e09\u7a2e\u53ef\u80fd\u7684\u72c0\u614b\uff1a<\/p>\n<ul>\n<li><strong>Enforcing<\/strong>\uff1aSELinux \u6b63\u5728\u5f37\u5236\u57f7\u884c\u5b89\u5168\u7b56\u7565\u3002<\/li>\n<li><strong>Permissive<\/strong>\uff1aSELinux \u5141\u8a31\u6240\u6709\u64cd\u4f5c\uff0c\u4f46\u6703\u8a18\u9304\u9055\u898f\u884c\u70ba\u3002<\/li>\n<li><strong>Disabled<\/strong>\uff1aSELinux \u5df2\u88ab\u7981\u7528\u3002<\/li>\n<\/ul>\n<p>\u60a8\u4e5f\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u7372\u53d6\u66f4\u8a73\u7d30\u7684\u72c0\u614b\u4fe1\u606f\uff1a<\/p>\n<pre><code>sestatus<\/code><\/pre>\n<p>\u9019\u500b\u547d\u4ee4\u6703\u986f\u793a SELinux \u7684\u72c0\u614b\u3001\u6a21\u5f0f\u548c\u7b56\u7565\u7b49\u4fe1\u606f\u3002<\/p>\n<h2 id=\"%e7%a6%81%e7%94%a8-selinux-wyPNIhkvDo\">\u7981\u7528 SELinux<\/h2>\n<p>\u5982\u679c\u60a8\u6c7a\u5b9a\u7981\u7528 SELinux\uff0c\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u6b65\u9a5f\u4f86\u5be6\u73fe\uff1a<\/p>\n<h3 id=\"1-%e7%b7%a8%e8%bc%af%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6-wyPNIhkvDo\">1. \u7de8\u8f2f\u914d\u7f6e\u6587\u4ef6<\/h3>\n<p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u7de8\u8f2f SELinux \u7684\u914d\u7f6e\u6587\u4ef6\u3002\u4f7f\u7528\u60a8\u559c\u6b61\u7684\u6587\u672c\u7de8\u8f2f\u5668\uff08\u4f8b\u5982 vi \u6216 nano\uff09\u6253\u958b\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre><code>sudo vi \/etc\/selinux\/config<\/code><\/pre>\n<p>\u5728\u6587\u4ef6\u4e2d\uff0c\u627e\u5230\u4ee5\u4e0b\u884c\uff1a<\/p>\n<pre><code>SELINUX=enforcing<\/code><\/pre>\n<p>\u5c07\u5176\u66f4\u6539\u70ba\uff1a<\/p>\n<pre><code>SELINUX=disabled<\/code><\/pre>\n<h3 id=\"2-%e4%bf%9d%e5%ad%98%e4%b8%a6%e9%80%80%e5%87%ba-wyPNIhkvDo\">2. \u4fdd\u5b58\u4e26\u9000\u51fa<\/h3>\n<p>\u4fdd\u5b58\u66f4\u6539\u4e26\u9000\u51fa\u7de8\u8f2f\u5668\u3002\u5c0d\u65bc vi \u7de8\u8f2f\u5668\uff0c\u60a8\u53ef\u4ee5\u6309 <code>Esc<\/code> \u9375\uff0c\u7136\u5f8c\u8f38\u5165 <code>:wq<\/code> \u4f86\u4fdd\u5b58\u4e26\u9000\u51fa\u3002<\/p>\n<h3 id=\"3-%e9%87%8d%e5%95%9f%e7%b3%bb%e7%b5%b1-wyPNIhkvDo\">3. \u91cd\u555f\u7cfb\u7d71<\/h3>\n<p>\u70ba\u4e86\u4f7f\u66f4\u6539\u751f\u6548\uff0c\u60a8\u9700\u8981\u91cd\u555f\u7cfb\u7d71\uff1a<\/p>\n<pre><code>sudo reboot<\/code><\/pre>\n<h2 id=\"%e8%87%a8%e6%99%82%e7%a6%81%e7%94%a8-selinux-wyPNIhkvDo\">\u81e8\u6642\u7981\u7528 SELinux<\/h2>\n<p>\u5982\u679c\u60a8\u4e0d\u60f3\u6c38\u4e45\u7981\u7528 SELinux\uff0c\u53ef\u4ee5\u9078\u64c7\u81e8\u6642\u7981\u7528\u5b83\u3002\u9019\u6a23\u505a\u4e0d\u9700\u8981\u91cd\u555f\u7cfb\u7d71\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>setenforce 0<\/code><\/pre>\n<p>\u9019\u5c07\u628a SELinux \u7684\u6a21\u5f0f\u8a2d\u7f6e\u70ba Permissive\uff0c\u76f4\u5230\u4e0b\u6b21\u91cd\u555f\u3002<\/p>\n<h2 id=\"%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-wyPNIhkvDo\">\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u7981\u7528 SELinux \u53ef\u80fd\u6703\u4f7f\u7cfb\u7d71\u9762\u81e8\u5b89\u5168\u98a8\u96aa\uff0c\u56e0\u6b64\u5728\u751f\u7522\u74b0\u5883\u4e2d\u61c9\u8b39\u614e\u64cd\u4f5c\u3002\u5982\u679c\u60a8\u9700\u8981\u7981\u7528 SELinux\uff0c\u5efa\u8b70\u60a8\u5728\u5b8c\u6210\u5fc5\u8981\u7684\u6e2c\u8a66\u6216\u958b\u767c\u5f8c\uff0c\u91cd\u65b0\u555f\u7528\u5b83\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-wyPNIhkvDo\">\u7e3d\u7d50<\/h2>\n<p>\u5728 CentOS 7.5 \u4e0a\u67e5\u770b\u548c\u7981\u7528 SELinux \u662f\u4e00\u500b\u76f8\u5c0d\u7c21\u55ae\u7684\u904e\u7a0b\u3002\u901a\u904e\u4f7f\u7528 <code>getenforce<\/code> \u548c <code>sestatus<\/code> \u547d\u4ee4\uff0c\u60a8\u53ef\u4ee5\u8f15\u9b06\u67e5\u770b SELinux \u7684\u7576\u524d\u72c0\u614b\u3002\u5982\u679c\u9700\u8981\u7981\u7528 SELinux\uff0c\u60a8\u53ef\u4ee5\u7de8\u8f2f\u914d\u7f6e\u6587\u4ef6\u4e26\u91cd\u555f\u7cfb\u7d71\uff0c\u6216\u4f7f\u7528 <code>setenforce<\/code> \u547d\u4ee4\u9032\u884c\u81e8\u6642\u7981\u7528\u3002\u7121\u8ad6\u5982\u4f55\uff0c\u8acb\u52d9\u5fc5\u8003\u616e\u5230\u5b89\u5168\u6027\uff0c\u4e26\u5728\u5fc5\u8981\u6642\u91cd\u65b0\u555f\u7528 SELinux\u3002\u82e5\u60a8\u5c0d\u65bc <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u6216\u5176\u4ed6 <a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a> \u89e3\u6c7a\u65b9\u6848\u6709\u8208\u8da3\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u4ee5\u7372\u53d6\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u5982\u4f55\u5728 CentOS 7.5 \u4e0a\u67e5\u770b\u548c\u7981\u7528 SELinux\uff0c\u786e\u4fdd\u7cfb\u7edf\u5b89\u5168\u6027\u4e0e\u7075\u6d3b\u6027\u4e4b\u95f4\u7684\u5e73\u8861\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-45278","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/45278","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=45278"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/45278\/revisions"}],"predecessor-version":[{"id":45279,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/45278\/revisions\/45279"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=45278"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=45278"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=45278"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}