{"id":79095,"date":"2026-11-17T02:03:28","date_gmt":"2026-11-17T02:03:28","guid":{"rendered":"http:\/\/bangla.sitestree.com\/?p=79095"},"modified":"2026-11-17T02:03:28","modified_gmt":"2026-11-17T02:03:28","slug":"linux-advanced-2-01-hardening","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=79095","title":{"rendered":"Linux Advanced 2 01 \u2014 Hardening a systemd Service"},"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=1993\">Linux Advanced 2 category<\/a> \u00b7 Lesson 1 of 7<\/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 extension adds new material and links related posts from this site. 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\">Run a small systemd service with a dedicated dynamic identity and a narrow writable directory.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Concepts and setup<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The site&#8217;s boot, logging, and SELinux posts explain separate layers of service control. This extension adds systemd isolation. DynamicUser allocates a temporary identity. StateDirectory provides one managed writable path. ProtectSystem=strict otherwise makes the service\u2019s filesystem view mostly read-only. NoNewPrivileges blocks privilege gains through execution. Use a disposable systemd VM, an unused unit name, and console access. Check application behavior separately from the security score.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Write and start the restricted unit<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo tee \/etc\/systemd\/system\/oe-linux-hardening.service &gt;\/dev\/null &lt;&lt;'EOF'\n[Unit]\nDescription=Open Education service isolation lab\n[Service]\nType=oneshot\nDynamicUser=yes\nStateDirectory=oe-linux-hardening\nProtectSystem=strict\nProtectHome=yes\nNoNewPrivileges=yes\nPrivateTmp=yes\nExecStart=\/usr\/bin\/touch \/var\/lib\/oe-linux-hardening\/check\nExecStart=\/usr\/bin\/echo state-write-ok\nEOF\nsudo systemd-analyze verify \/etc\/systemd\/system\/oe-linux-hardening.service\nsudo systemctl daemon-reload\nsudo systemctl start oe-linux-hardening.service\nsudo journalctl -u oe-linux-hardening.service -n 8 --no-pager\nsudo test -f \/var\/lib\/oe-linux-hardening\/check &amp;&amp; printf 'proof exists\\n'<\/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>... state-write-ok\n... Finished Open Education service isolation lab.\nproof exists<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">StateDirectory is an explicit writable exception to the service\u2019s read-only view. A successful oneshot can be inactive after the command exits.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Inspect controls and remove the fixture unit<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl show oe-linux-hardening.service -p DynamicUser -p NoNewPrivileges -p ProtectSystem\nsystemd-analyze security oe-linux-hardening.service\nsudo systemctl stop oe-linux-hardening.service\nsudo rm \/etc\/systemd\/system\/oe-linux-hardening.service\nsudo systemctl daemon-reload<\/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>DynamicUser=yes\nNoNewPrivileges=yes\nProtectSystem=strict\n...\nOverall exposure level for oe-linux-hardening.service: ...<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The score is a checklist aid, not a guarantee. Removing the unit does not remove persistent state. Retire the named lab directory after recording results.<\/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>Which directive supplies the writable directory?<\/li>\n\n\n<li>Does a good security score demonstrate that the application works?<\/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>Why use controls and an application check?<\/li>\n\n\n<li>Name two controls that restrict this unit at the operating-system level.<\/li>\n\n\n<li>ProtectHome breaks a service. How might you keep that control without breaking the service?<\/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>Which directive supplies the writable directory?<\/strong><br><strong>Answer<\/strong> \u2014 StateDirectory, here for oe-linux-hardening.<\/li>\n\n\n<li><strong>Does a good security score demonstrate that the application works?<\/strong><br><strong>Answer<\/strong> \u2014 No. Verify the task outcome and logs.<\/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>Why use controls and an application check?<\/strong><br><strong>Answer<\/strong> \u2014 Controls reduce what is accessible. A check confirms the service can still do its intended work.<\/li>\n\n\n<li><strong>Name two controls that restrict this unit at the operating-system level.<\/strong><br><strong>Answer<\/strong> \u2014 Examples include DynamicUser, ProtectSystem, NoNewPrivileges, ProtectHome, and PrivateTmp.<\/li>\n\n\n<li><strong>ProtectHome breaks a service. How might you keep that control without breaking the service?<\/strong><br><strong>Answer<\/strong> \u2014 Move only necessary inputs to a managed application directory with narrowly scoped access and retest.<\/li>\n\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Related 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=78691\">Q &amp; A:  Linux: Switch Users, Boot Process, File System<\/a><\/li>\n\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=67588\">Experiment with Firewalls in Linux (CentOS\/RedHat) #DevOps #RHCSA<\/a><\/li>\n\n\n<li><a href=\"https:\/\/bangla.sitestree.com\/?p=9949\">\u0987\u0989\u09a8\u09bf\u0995\u09cd\u09b8\u0983 \u09b8\u09bf\u09b8\u09cd\u099f\u09c7\u09ae \u09b2\u0997\u09bf\u0982 (Unix \u2013 System Logging)<\/a><\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Technical references<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n\n<li><a href=\"https:\/\/freedesktop.org\/software\/systemd\/man\/latest\/systemd.exec.html\">systemd execution directives<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.freedesktop.org\/software\/systemd\/man\/latest\/systemd-analyze.html\">systemd-analyze manual<\/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\">Next lesson 02 \u2014 Rootless Containers with Podman.<\/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=1993\">Linux Advanced 2 category<\/a> \u00b7 Lesson 1 of 7<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Run a small systemd service with a dedicated dynamic identity and a narrow writable directory.<\/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":[1993],"tags":[],"class_list":["post-79095","post","type-post","status-publish","format-standard","hentry","category-linux-advanced-2","item-wrap"],"jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":79082,"url":"http:\/\/bangla.sitestree.com\/?p=79082","url_meta":{"origin":79095,"position":0},"title":"Linux Intermediate 06 \u2014 Boot, Services, Logs, and Timers","author":"Sayed","date":"November 17, 2026","format":false,"excerpt":"Trace the boot-to-service path, inspect logs, and create a timer that runs a tiny user service.","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":79102,"url":"http:\/\/bangla.sitestree.com\/?p=79102","url_meta":{"origin":79095,"position":1},"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":79096,"url":"http:\/\/bangla.sitestree.com\/?p=79096","url_meta":{"origin":79095,"position":2},"title":"Linux Advanced 2 02 \u2014 Rootless Containers with Podman","author":"Sayed","date":"November 17, 2026","format":false,"excerpt":"Serve a fixture with rootless Podman and verify that its port is published only on loopback.","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":79092,"url":"http:\/\/bangla.sitestree.com\/?p=79092","url_meta":{"origin":79095,"position":3},"title":"Linux Advanced 07 \u2014 Time Synchronization with chrony","author":"Sayed","date":"November 17, 2026","format":false,"excerpt":"Distinguish clock display from synchronization and show whether chrony selected a source.","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":[]},{"id":78691,"url":"http:\/\/bangla.sitestree.com\/?p=78691","url_meta":{"origin":79095,"position":4},"title":"Q &amp; A:  Linux: Switch Users, Boot Process, File System","author":"Sayed","date":"June 1, 2026","format":false,"excerpt":"Quiz: Root Access, Boot Process, File Systems, Partitions, and Mounting 1. True\/False The root user is the superuser account and has the highest access rights on a Linux system. Answer: True 2. True\/False It is recommended to stay logged in as root for normal daily work because it is faster.\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":14031,"url":"http:\/\/bangla.sitestree.com\/?p=14031","url_meta":{"origin":79095,"position":5},"title":"Network Interface, Network Clients related Linux\/Redhat\/CentOS commands","author":"Sayed","date":"December 24, 2017","format":false,"excerpt":"echo \"Dec 24th, 2017\" 532 echo \"Basic Networking in Linux\" 533 hostname 534 uname -a 535 uname -n 536 cat \/etc\/hostname 537 nmcli general hostname 538 changing hostname temporarily 539 hostname server10.example.com 540 for permanent change 541 hostnamectl set-hostname server100.example.com 542 or change \/etc\/hostname file 543 vim \/etc\/hostname 544 restart\u2026","rel":"","context":"In &quot;\u09b2\u09bf\u09a8\u09be\u0995\u09cd\u09b8 \u098f\u09ac\u0982 \u0989\u09a8\u09bf\u0995\u09cd\u09b8 \u0964 Linux and Unix&quot;","block_context":{"text":"\u09b2\u09bf\u09a8\u09be\u0995\u09cd\u09b8 \u098f\u09ac\u0982 \u0989\u09a8\u09bf\u0995\u09cd\u09b8 \u0964 Linux and Unix","link":"http:\/\/bangla.sitestree.com\/?cat=1231"},"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\/79095","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=79095"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/79095\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=79095"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=79095"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=79095"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}