{"id":293,"date":"2019-03-31T23:38:03","date_gmt":"2019-03-31T15:38:03","guid":{"rendered":"https:\/\/www.aiqinqin.info\/?p=293"},"modified":"2019-03-31T23:42:02","modified_gmt":"2019-03-31T15:42:02","slug":"linux%e4%b9%8bselinux","status":"publish","type":"post","link":"https:\/\/www.aiqinqin.info\/?p=293","title":{"rendered":"Linux\u4e4bSELINUX"},"content":{"rendered":"<ul>\n<li>\u8eab\u4efd\u8bc6\u522b(Identify)<\/li>\n<\/ul>\n<pre><code class=\"\">root        --- \u8868\u793aroot\u7684\u8d26\u53f7\u8eab\u4efd\nsystem_u    --- \u8868\u793a\u7cfb\u7edf\u7a0b\u5e8f\u65b9\u9762\u7684\u8bc6\u522b\uff0c\u901a\u5e38\u5c31\u662f\u7a0b\u5e8f\nuser_u      --- \u4ee3\u8868\u4e00\u822c\u7528\u6237\u8d26\u53f7\u76f8\u5173\u7684\u8eab\u4efd\n<\/code><\/pre>\n<ul>\n<li>\u89d2\u8272(Role)<\/li>\n<\/ul>\n<pre><code class=\"\">object_r    --- \u4ee3\u8868\u7684\u662f\u6587\u4ef6\u6216\u76ee\u5f55\u7b49\u6587\u4ef6\u8d44\u6e90\uff0c\u8fd9\u662f\u6700\u5e38\u89c1\u7684\nsystem_r    --- \u4ee3\u8868\u7684\u5c31\u662f\u7a0b\u5e8f\uff0c\u4e0d\u8fc7\u4e00\u822c\u7528\u6237\u4e5f\u4f1a\u88ab\u6307\u5b9a\u4e3asystem_r\n<\/code><\/pre>\n<ul>\n<li>\u7c7b\u578b(Type)<\/li>\n<\/ul>\n<pre><code class=\"\">Type        --- \u5728\u6587\u4ef6\u8d44\u6e90(object)\u4e2d\u79f0\u4e3a\u7c7b\u578b(Type)\nDomain      --- \u5728\u4e3b\u4f53\u7a0b\u5e8f(Subject)\u4e2d\u5219\u79f0\u4e3a\u57df(Domain)\n<\/code><\/pre>\n<ul>\n<li>\u5f53\u4f60\u5728\u5355\u7eaf\u5730\u590d\u5236\u65f6\uff0cSELinux\u7684Type\u5b57\u6bb5\u4f1a\u7ee7\u627f\u81ea\u76ee\u6807\u76ee\u5f55\uff0c\u5982\u679c\u662f\u79fb\u52a8\u7684\u8bdd\u5c31\u4f1a\u8fde\u540cSELinux\u7684\u7c7b\u578b\u4e5f\u4f1a\u88ab\u79fb\u52a8\u8fc7\u53bb<\/li>\n<li>\u5e38\u7528\u547d\u4ee4\u4ee5\u53ca\u4e00\u4e9b\u53c2\u6570\uff1a<\/li>\n<\/ul>\n<pre><code class=\"\">chcon       --- \u6539\u53d8SELinux\u7684\u72b6\u6001\n    -R              --- \u8fde\u540c\u8be5\u76ee\u5f55\u4e0b\u7684\u5b50\u76ee\u5f55\u4e5f\u540c\u65f6\u4fee\u6539\n    -t              --- \u540e\u9762\u63a5\u5b89\u5168\u6027\u73af\u5883\u7684\u7c7b\u578b\u5b57\u6bb5\n    -u              --- \u540e\u9762\u63a5\u8eab\u4efd\u8bc6\u522b\n    -r              --- \u540e\u9762\u63a5\u89d2\u8272\n    --reference     --- \u62ff\u67d0\u4e2a\u6587\u4ef6\u5f53\u8303\u4f8b\u6765\u4fee\u6539\u540e\u7eed\u63a5\u7684\u6587\u4ef6\u7c7b\u578b\nrestorecon [-Rv] file|dir   --- \u6062\u590d\u6210\u539f\u6709\u7684SELinux Type\u7c7b\u578b\n    -R          --- \u8fde\u540c\u5b50\u76ee\u5f55\u4e00\u8d77\u4fee\u6539\n    -v          --- \u5c06\u8fc7\u7a0b\u663e\u793a\u5230\u5c4f\u5e55\u4e0a \nsemanage fcontext -l -{a|d|m} [-frst] file_spec --- \u5982\u679c\u6ca1\u6709semanage\u8fd9\u4e2a\u547d\u4ee4\uff0c\u9700\u8981\u5148\u7528\"yum install policycoreutils-python\"\n    -l      --- \u8868\u793a\u67e5\u8be2\u7684\u610f\u601d\n    -a      --- \u589e\u52a0\u4e00\u4e2a\u9ed8\u8ba4\u7c7b\u578b\n    -m      --- \u4fee\u6539\u4e00\u4e2a\u9ed8\u8ba4\u914d\u7f6e\n    -d      --- \u5220\u9664\u4e00\u4e2a\u9ed8\u8ba4\u7684\u914d\u7f6e\nseinfo [-Atrub]         --- \u67e5\u770b\u7b56\u7565\u63d0\u4f9b\u7684\u89c4\u5219\uff0c\u5982\u679c\u6ca1\u6709\u8fd9\u4e2a\u547d\u4ee4\uff0c\u9700\u8981\u4f7f\u7528\u547d\u4ee4\"yum  install setools-console\"\u5b89\u88c5\n    -A      --- \u5217\u51faSELinux\u7684\u72b6\u6001\u3001\u89c4\u5219\u5e03\u5c14\u503c\u3001\u8eab\u4efd\u8bc6\u522b\u3001\u89d2\u8272\u3002\u7c7b\u522b\u7b49\u6240\u6709\u4fe1\u606f\n    -t      --- \u5217\u51faSELinux\u7684\u6240\u6709\u7c7b\u522b(type)\u7684\u79cd\u7c7b\n    -r      --- \u5217\u51faSELinux\u7684\u6240\u6709\u89d2\u8272(role)\u79cd\u7c7b\n    -u      --- \u5217\u51faSELinux\u7684\u6240\u6709\u8eab\u4efd\u8bc6\u522b(user)\u79cd\u7c7b\n    -b      --- \u5217\u51fa\u6240\u6709\u89c4\u5219\u7684\u79cd\u7c7b(\u5e03\u5c14\u503c)\n    sesearch [--all] [-s \u4e3b\u4f53\u7c7b\u522b] [-t \u76ee\u6807\u7c7b\u578b] [-b \u5e03\u5c14\u503c]   --- \u67e5\u8be2\u8be6\u7ec6\u7684\u89c4\u5219\n    --all   --- \u5217\u51fa\u8be5\u7c7b\u522b\u6216\u5e03\u5c14\u503c\u7684\u6240\u6709\u76f8\u5173\u4fe1\u606f\ngetsebool -a        --- \u67e5\u8be2\u7cfb\u7edf\u5185\u6240\u6709\u7684\u5e03\u5c14\u503c\u8bbe\u7f6e\u72b6\u51b5\nsetsebool [-P] \u5e03\u5c14\u503c=[0|1]        --- \u8bbe\u7f6e\u5e03\u5c14\u503c\n    -P      --- \u76f4\u63a5\u5c06\u8bbe\u7f6e\u5199\u5165\u914d\u7f6e\u6587\u4ef6\uff0c\u91cd\u542f\u540e\u4f9d\u7136\u6709\u6548\nsetrouobleshoot ---\u8fd9\u4e2a\u670d\u52a1\u4f1a\u5c06\u5173\u4e8eSELinux\u7684\u9519\u8bef\u4fe1\u606f\u4e0e\u89e3\u51b3\u65b9\u6cd5\u8bb0\u5f55\u5230\/var\/log\/messages\u4e0e\/var\/log\/setroubleshoot\/*\u4e2d\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1ayum install setroubleshoot setroubleshoot-server.\u6392\u9519\u7684\u6b65\u9aa4\u5c31\u662f\u6839\u636e\/var\/log\/messages\u4e2d\u7684setroubleshoot\u9519\u8bef\u4fe1\u606f\uff0c\u6309\u7167\u63d0\u793a\u8fdb\u884c\u5c31\u53ef\u4ee5\u4e86\n\/etc\/init.d\/auditd restart\n<\/code><\/pre>\n<ul>\n<li>\u4e00\u4e9b\u793a\u4f8b<\/li>\n<\/ul>\n<pre><code class=\"\">semanage fcontext -l | grep '\/var\/www'      --- \u67e5\u8be2\/var\/www\u76ee\u5f55\u4e0b\u7684\u9ed8\u8ba4\u7c7b\u578b\u6709\u54ea\u4e9b\nmkdir \/opt\/web  --- \u6211\u4eec\u5728\/srv\u4e0b\u521b\u5efa\u4e86\u4e00\u4e2a\u76ee\u5f55\u5e76\u4e14\u901a\u8fc7\u4e0b\u9762\u8fd9\u4e2a\u547d\u4ee4\u628a\u4ed6\u7684\u9ed8\u8ba4\u7c7b\u578b\u8bbe\u7f6e\u4e3apublic_content_t\u7c7b\u578b\nsemanage fcontext -a -t public_content_t \"\/opt\/web(\/.*)?\"\n<\/code><\/pre>\n<blockquote><p>\n  PS:\u5982\u679c\u4ecedisable\u8f6c\u5230\u542f\u52a8SELinux\u7684\u6a21\u5f0f\u65f6\uff0c\u7531\u4e8e\u7cfb\u7edf\u5fc5\u987b\u8981\u9488\u5bf9\u6587\u4ef6\u5199\u5165\u5b89\u5168\u6027\u73af\u5883\u7684\u4fe1\u606f\uff0c\u56e0\u6b64\u5f00\u673a\u8fc7\u7a0b\u4f1a\u82b1\u8d39\u4e0d\u5c11\u65f6\u95f4\u6765\u7b49\u5f85\u91cd\u65b0\u5199\u5165SELinux\u5b89\u5168\u6027\u73af\u5883(\u6709\u65f6\u5019\u4e5f\u79f0\u4e3aSELinux Label)\uff0c\u800c\u4e14\u5728\u5199\u5b8c\u4e4b\u540e\u8fd8\u9700\u8981\u518d\u6b21\u91cd\u65b0\u542f\u52a8\u4e00\u6b21\uff0c\u8fd9\u9700\u8981\u7b49\u5f85\u5f88\u957f\u4e00\u6bb5\u65f6\u95f4\uff1b\u5982\u679c\u5728\u91cd\u65b0\u5199\u5165SELinux Type(Relable)\u65f6\u51fa\u9519\uff0c\u53ef\u4ee5\u4f7f\u7528&#8221;restorecon -Rv \/&#8221;\u91cd\u65b0\u8fd8\u539fSELinux\u7684\u7c7b\u578b\uff0c\u5c31\u53ef\u4ee5\u5904\u7406\u4e86\n<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>\u8eab\u4efd\u8bc6\u522b(Identify) root &#8212; \u8868\u793aroot\u7684\u8d26\u53f7\u8eab\u4efd system_u &#8212; \u8868\u793a\u7cfb\u7edf\u7a0b\u5e8f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-293","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=\/wp\/v2\/posts\/293","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=293"}],"version-history":[{"count":3,"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=\/wp\/v2\/posts\/293\/revisions"}],"predecessor-version":[{"id":296,"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=\/wp\/v2\/posts\/293\/revisions\/296"}],"wp:attachment":[{"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}