{"id":82196,"date":"2023-10-11T18:36:33","date_gmt":"2023-10-11T10:36:33","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=82196"},"modified":"2023-10-11T18:36:33","modified_gmt":"2023-10-11T10:36:33","slug":"semanage","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/semanage.html","title":{"rendered":"semanage\u547d\u4ee4\u8be6\u89e3"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nsemanage\u547d\u4ee4\u662f\u7528\u6765\u67e5\u8be2\u4e0e\u4fee\u6539SELinux\u9ed8\u8ba4\u76ee\u5f55\u7684\u5b89\u5168\u4e0a\u4e0b\u6587\u3002SELinux\u7684\u7b56\u7565\u4e0e\u89c4\u5219\u7ba1\u7406\u76f8\u5173\u547d\u4ee4\uff1aseinfo\u547d\u4ee4\u3001sesearch\u547d\u4ee4\u3001getsebool\u547d\u4ee4\u3001setsebool\u547d\u4ee4\u3001semanage\u547d\u4ee4\u3002<\/strong>\u4e0b\u9762\u8ba9\u6211\u4eec\u8be6\u7ec6\u8bb2\u89e3\u4e00\u4e0bchcon\u547d\u4ee4\u7684\u4f7f\u7528\u65b9\u6cd5\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u8bed\u6cd5<\/b><\/div>\n
semanage {login|user|port|interface|fcontext|translation} -l \r\nsemanage fcontext -{a|d|m} [-frst] file_spec<\/pre>\n
\u9009\u9879<\/b><\/div>\n
--l\uff1a\u67e5\u8be2\u3002 \r\nfcontext\uff1a\u4e3b\u8981\u7528\u5728\u5b89\u5168\u4e0a\u4e0b\u6587\u65b9\u9762\u3002 \r\n-a\uff1a\u589e\u52a0\uff0c\u4f60\u53ef\u4ee5\u589e\u52a0\u4e00\u4e9b\u76ee\u5f55\u7684\u9ed8\u8ba4\u5b89\u5168\u4e0a\u4e0b\u6587\u7c7b\u578b\u8bbe\u7f6e\u3002 \r\n-m\uff1a\u4fee\u6539\u3002 \r\n-d\uff1a\u5220\u9664\u3002<\/pre>\n
\u5b9e\u4f8b<\/b><\/div>\n
\u67e5\u8be2\u4e00\u4e0b\/var\/www\/html<\/span>\u7684\u9ed8\u8ba4\u5b89\u5168\u6027\u672c\u6587\u7684\u8bbe\u7f6e\uff1a
\n<\/strong><\/span><\/div>\n
semanage fcontext -l \r\nSELinux fcontext type Context \r\n....(\u524d\u9762\u7701\u7565).... \/var\/www(\/.*)? all files system_u:object_r:httpd_sys_content_t:s0 ....(\u5f8c\u9762\u7701\u7565)....\r\n<\/pre>\n

\u5982\u4e0a\u9762\u4f8b\u5b50\u6240\u793a\uff0c\u6211\u4eec\u53ef\u4ee5\u67e5\u8be2\u7684\u5230\u6bcf\u4e2a\u76ee\u5f55\u7684\u5b89\u5168\u6027\u672c\u6587\uff01\u800c\u76ee\u5f55\u7684\u8bbe\u5b9a\u53ef\u4ee5\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u53bb\u6307\u5b9a\u4e00\u4e2a\u8303\u56f4\u3002\u90a3\u4e48\u5982\u679c\u6211\u4eec\u60f3\u8981\u589e\u52a0\u67d0\u4e9b\u81ea\u5b9a\u4e49\u76ee\u5f55\u7684\u5b89\u5168\u6027\u672c\u6587\u5462\uff1f\u4e3e\u4f8b\u6765\u8bf4\uff0c\u6211\u60f3\u8981\u8272\u8bbe\u7f6e\/srv\/samba<\/span>\u6210\u4e3a public_content_t\u5185\u8054\u4ee3\u7801<\/span>\u7684\u7c7b\u578b\u65f6\uff0c\u5e94\u8be5\u5982\u4f55\u8bbe\u7f6e\u5462\uff1f<\/p>\n

\u7528semanage<\/span>\u547d\u4ee4\u8bbe\u7f6e\/srv\/samba<\/span>\u76ee\u5f55\u7684\u9ed8\u8ba4\u5b89\u5168\u6027\u672c\u6587\u4e3apublic_content_t<\/span>\uff1a
\n<\/strong><\/span><\/div>\n
chcon -t public_content_rw_t \/var\/ftp\/incoming<\/pre>\n
\u5141\u8bb8\u7528\u6237HHTP\u8bbf\u95ee\u5176\u5bb6\u76ee\u5f55\uff0c\u8be5\u8bbe\u5b9a\u9650\u4ec5\u4e8e\u7528\u6237\u7684\u5bb6\u76ee\u5f55\u4e3b\u9875\uff1a
\n<\/strong><\/span><\/div>\n
mkdir \/srv\/samba \r\nll -Zd \/srv\/samba \r\ndrwxr-xr-x root root root:object_r:var_t \/srv\/samba<\/pre>\n
\u5982\u4e0a\u6240\u793a\uff0c\u9ed8\u8ba4\u7684\u60c5\u51b5\u5e94\u8be5\u662fvar_t<\/span>\u8fd9\u4e2a\u549a\u549a\u7684\uff01
\n<\/strong><\/span><\/div>\n
semanage fcontext -l | grep '\/srv' \r\n\/srv\/.* all files system_u:object_r:var_t:s0 \r\n\/srv\/([^\/]*\/)?ftp(\/.*)? all files system_u:object_r:public_content_t:s0 \r\n\/srv\/([^\/]*\/)?www(\/.*)? all files system_u:object_r:httpd_sys_content_t:s0 \/srv\/([^\/]*\/)?rsync(\/.*)? all files system_u:object_r:public_content_t:s0 \/srv\/gallery2(\/.*)? all files system_u:object_r:httpd_sys_content_t:s0 \r\n\/srv directory system_u:object_r:var_t:s0 \/\/\u770b\u8fd9\u91cc\uff01\r\n<\/pre>\n
\u4e0a\u9762\u5219\u662f\u9ed8\u8ba4\u7684\/srv\u5e95\u4e0b\u7684\u5b89\u5168\u6027\u672c\u6587\u8d44\u6599\uff0c\u4e0d\u8fc7\uff0c\u5e76\u6ca1\u6709\u6307\u5b9a\u5230\/srv\/samba<\/span>\u3002
\n<\/strong><\/span><\/div>\n
semanage fcontext -a -t public_content_t \"\/srv\/samba(\/.*)?\" \r\nsemanage fcontext -l | grep '\/srv\/samba' \r\n\/srv\/samba(\/.*)? all files system_u:object_r:public_content_t:s0\r\n<\/pre>\n
cat \/etc\/selinux\/targeted\/contexts\/files\/file_contexts.local \r\n# This file is auto-generated by libsemanage # Please use the semanage command to make changes \r\n\/srv\/samba(\/.*)? system_u:object_r:public_content_t:s0 #\u5199\u5165\u8fd9\u4e2a\u6863\u6848\r\n<\/pre>\n
restorecon -Rv \/srv\/samba* #\u5c1d\u8bd5\u6062\u590d\u9ed8\u8ba4\u503c ll -Zd \/srv\/samba drwxr-xr-x root root system_u:object_r:public_content_t \/srv\/samba\/ #\u6709\u9ed8\u8ba4\u503c\uff0c\u4ee5\u540e\u7528restorecon\u547d\u4ee4\u6765\u4fee\u6539\u6bd4\u8f83\u7b80\u5355\uff01\r\n<\/pre>\n
\n

\u539f\u6587\u6765\u81ea\uff1ahttp:\/\/man.linuxde.net\/semanage<\/a><\/p>\n

\u672c\u6587\u5730\u5740\uff1ahttp:\/\/lrxjmw.cn\/semanage.html<\/a>\u7f16\u8f91\uff1a\u738b\u6bc5\uff0c\u5ba1\u6838\u5458\uff1a\u51af\u742a<\/span><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"

\u5bfc\u8bfb semanage\u547d\u4ee4\u662f\u7528\u6765\u67e5\u8be2\u4e0e\u4fee\u6539SELinux\u9ed8\u8ba4\u76ee\u5f55\u7684\u5b89\u5168\u4e0a\u4e0b\u6587\u3002SELinux\u7684\u7b56\u7565\u4e0e\u89c4\u5219\u7ba1\u7406\u76f8 […]<\/p>\n","protected":false},"author":564,"featured_media":82220,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-82196","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\/82196","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\/564"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=82196"}],"version-history":[{"count":5,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/82196\/revisions"}],"predecessor-version":[{"id":82217,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/82196\/revisions\/82217"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/82220"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=82196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=82196"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=82196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}