{"id":79088,"date":"2026-11-17T01:59:48","date_gmt":"2026-11-17T01:59:48","guid":{"rendered":"http:\/\/bangla.sitestree.com\/?p=79088"},"modified":"2026-11-17T01:59:48","modified_gmt":"2026-11-17T01:59:48","slug":"linux-advanced-03-selinux","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=79088","title":{"rendered":"Linux Advanced 03 \u2014 SELinux Contexts, Booleans, and Denials"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/bangla.sitestree.com\/?name=linux-course-index\">Linux course index<\/a> \u00b7 <a href=\"https:\/\/bangla.sitestree.com\/?cat=1992\">Linux Advanced category<\/a> \u00b7 Lesson 3 of 9<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>AI disclosure<\/strong> \u2014 AI-generated content, posted as is. AI can make mistakes. This lesson draws on the linked Open Education posts and adds original explanations or lab examples where useful. The newly written explanations and examples may be freely reused. Linked source material retains its own terms.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Learning goal<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Diagnose ordinary permission and SELinux policy problems separately and set a persistent file context.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Concepts and setup<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">SELinux adds a mandatory policy check to ordinary mode bits and ACLs. A mode of 0644 does not guarantee that a confined service can read a file. Enforcing applies policy, permissive records would-be denials, and disabled does not enforce. Booleans are documented policy toggles, not general fixes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use an enforcing Red Hat-family VM with Apache and the SELinux administration tools. The original site&#8217;s Apache example uses ls -Z, and its Boolean example uses getsebool. Keep enforcement on while following these lab steps.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Inspect policy and current labels<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>getenforce\nls -Zd \/var\/www\/html\nmatchpathcon \/var\/www\/html\/index.html\ngetsebool httpd_can_network_connect\nsudo ausearch -m AVC -ts recent<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Possible output<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Enforcing\nsystem_u:object_r:httpd_sys_content_t:s0 \/var\/www\/html\n\/var\/www\/html\/index.html system_u:object_r:httpd_sys_content_t:s0\nhttpd_can_network_connect --&gt; off\n&lt;no matches&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Inspect denial timestamps and the process, object type, and operation before acting. No matches does not prove that an HTTP request succeeded.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Set a persistent context for an unused lab content path<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo install -d -m 0755 \/srv\/oe-linux-content\nprintf 'SELinux lab\\n' | sudo tee \/srv\/oe-linux-content\/index.html\nsudo chmod 0644 \/srv\/oe-linux-content\/index.html\nsudo semanage fcontext -a -t httpd_sys_content_t '\/srv\/oe-linux-content(\/.*)?'\nsudo restorecon -Rv \/srv\/oe-linux-content\nls -Z \/srv\/oe-linux-content\/index.html\nmatchpathcon -V \/srv\/oe-linux-content\/index.html<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Possible output<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELinux lab\nRelabeled \/srv\/oe-linux-content\/index.html from ... to ...:httpd_sys_content_t:s0\n...:httpd_sys_content_t:s0 \/srv\/oe-linux-content\/index.html\n\/srv\/oe-linux-content\/index.html verified.<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The lab checks labels, not actual HTTP service. To roll back, remove the exact lab rule with semanage fcontext -d &#8216;\/srv\/oe-linux-content(\/.*)?&#8217; and remove the new fixture.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Questions only<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Quick-check questions<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n\n<li>Why can chmod 777 fail to resolve the denial?<\/li>\n\n\n<li>What does restorecon do?<\/li>\n\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Assessment questions<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n\n<li>A web server cannot read a new DocumentRoot. Which three layers would you check?<\/li>\n\n\n<li>Why use a persistent fcontext rule rather than a one-off label change?<\/li>\n\n\n<li>When is changing a Boolean justified?<\/li>\n\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Questions and answers<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Quick-check answers<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n\n<li><strong>Why can chmod 777 fail to resolve the denial?<\/strong><br><strong>Answer<\/strong> \u2014 SELinux is a separate check. Broadening normal access does not correct a policy denial or label.<\/li>\n\n\n<li><strong>What does restorecon do?<\/strong><br><strong>Answer<\/strong> \u2014 It applies the context expected by the configured file-context rules.<\/li>\n\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Assessment answer key<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n\n<li><strong>A web server cannot read a new DocumentRoot. Which three layers would you check?<\/strong><br><strong>Answer<\/strong> \u2014 Check normal permissions and traversal, Apache configuration and user, and SELinux labels plus AVC evidence.<\/li>\n\n\n<li><strong>Why use a persistent fcontext rule rather than a one-off label change?<\/strong><br><strong>Answer<\/strong> \u2014 A future relabel can apply the expected context again.<\/li>\n\n\n<li><strong>When is changing a Boolean justified?<\/strong><br><strong>Answer<\/strong> \u2014 When the intended workload actually requires the documented behavior, the relevant Boolean controls it, and a narrower solution is not appropriate.<\/li>\n\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Source articles on this site<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n\n<li><a href=\"https:\/\/bangla.sitestree.com\/?p=78684\">Define and describe Selinux in general terms<\/a><\/li>\n\n\n<li><a href=\"https:\/\/bangla.sitestree.com\/?p=78678\">Linux: ACL vs Selinux<\/a><\/li>\n\n\n<li><a href=\"https:\/\/bangla.sitestree.com\/?p=76574\">selinux: getsebool -a sample output<\/a><\/li>\n\n\n<li><a href=\"https:\/\/bangla.sitestree.com\/?p=78680\">Linux: Regular Permissions (symbolic\/numeric) vs ACL<\/a><\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Continue the course<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Previous lesson 02 \u2014 NFS and On-Demand Mounting with AutoFS. Next lesson 04 \u2014 Firewall Zones and Runtime Rules.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/bangla.sitestree.com\/?name=linux-course-index\">Linux course index<\/a> \u00b7 <a href=\"https:\/\/bangla.sitestree.com\/?cat=1992\">Linux Advanced category<\/a> \u00b7 Lesson 3 of 9<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Diagnose ordinary permission and SELinux policy problems separately and set a persistent file context.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[1992],"tags":[],"class_list":["post-79088","post","type-post","status-publish","format-standard","hentry","category-linux-advanced","item-wrap"],"jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":79102,"url":"http:\/\/bangla.sitestree.com\/?p=79102","url_meta":{"origin":79088,"position":0},"title":"Linux Administration Course \u2014 Start Here and Lesson Index","author":"Sayed","date":"November 17, 2026","format":false,"excerpt":"A 33-lesson Linux course from shell fundamentals to server administration, performance, and a recovery capstone.","rel":"","context":"In &quot;Linux Basics&quot;","block_context":{"text":"Linux Basics","link":"http:\/\/bangla.sitestree.com\/?cat=1990"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":78684,"url":"http:\/\/bangla.sitestree.com\/?p=78684","url_meta":{"origin":79088,"position":1},"title":"Define and describe Selinux in general terms","author":"Sayed","date":"May 30, 2026","format":false,"excerpt":"SELinux stands for Security-Enhanced Linux. It is a Linux security system that adds an extra layer of protection to the operating system. It controls what users, programs, services, and processes are allowed to do. A simple definition: SELinux is a security feature in Linux that enforces strict rules about which\u2026","rel":"","context":"In &quot;Anything Linux&quot;","block_context":{"text":"Anything Linux","link":"http:\/\/bangla.sitestree.com\/?cat=1976"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":78678,"url":"http:\/\/bangla.sitestree.com\/?p=78678","url_meta":{"origin":79088,"position":2},"title":"Linux: ACL vs Selinux","author":"Sayed","date":"May 30, 2026","format":false,"excerpt":"ACL vs SELinux ACL and SELinux both control access, but they work at different levels. FeatureACLSELinuxFull nameAccess Control ListSecurity-Enhanced LinuxMain purposeGive extra file permissions to specific users\/groupsEnforce system-wide security policyAccess modelDAC: Discretionary Access ControlMAC: Mandatory Access ControlControlled byFile owner\/rootSELinux policy\/rootWorks onFiles\/directoriesFiles, processes, ports, services, usersCommon commandsgetfacl, setfaclgetenforce, ls -Z, semanage,\u2026","rel":"","context":"In &quot;Anything Linux&quot;","block_context":{"text":"Anything Linux","link":"http:\/\/bangla.sitestree.com\/?cat=1976"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":79078,"url":"http:\/\/bangla.sitestree.com\/?p=79078","url_meta":{"origin":79088,"position":3},"title":"Linux Intermediate 02 \u2014 Access Control Lists and Shared Directories","author":"Sayed","date":"November 17, 2026","format":false,"excerpt":"Grant and remove a narrowly scoped named-user ACL and distinguish a grant from effective access.","rel":"","context":"In &quot;Linux Intermediate&quot;","block_context":{"text":"Linux Intermediate","link":"http:\/\/bangla.sitestree.com\/?cat=1991"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":79095,"url":"http:\/\/bangla.sitestree.com\/?p=79095","url_meta":{"origin":79088,"position":4},"title":"Linux Advanced 2 01 \u2014 Hardening a systemd Service","author":"Sayed","date":"November 17, 2026","format":false,"excerpt":"Run a small systemd service with a dedicated dynamic identity and a narrow writable directory.","rel":"","context":"In &quot;Linux Advanced 2&quot;","block_context":{"text":"Linux Advanced 2","link":"http:\/\/bangla.sitestree.com\/?cat=1993"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":79089,"url":"http:\/\/bangla.sitestree.com\/?p=79089","url_meta":{"origin":79088,"position":5},"title":"Linux Advanced 04 \u2014 Firewall Zones and Runtime Rules","author":"Sayed","date":"November 17, 2026","format":false,"excerpt":"Identify the active zone and compare a timed runtime firewall rule with permanent policy.","rel":"","context":"In &quot;Linux Advanced&quot;","block_context":{"text":"Linux Advanced","link":"http:\/\/bangla.sitestree.com\/?cat=1992"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/79088","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=79088"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/79088\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=79088"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=79088"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=79088"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}