{"id":873,"date":"2017-01-20T00:00:49","date_gmt":"2017-01-19T22:00:49","guid":{"rendered":"https:\/\/community.virtono.com\/?p=873"},"modified":"2017-01-24T19:35:01","modified_gmt":"2017-01-24T17:35:01","slug":"hardening-linux","status":"publish","type":"post","link":"https:\/\/www.virtono.com\/community\/knowledgebase\/hardening-linux\/","title":{"rendered":"Hardening Linux:OS Hardening Principles"},"content":{"rendered":"<p><strong>Hardening Linux and Using iptables<\/strong><\/p>\n<p class=\"docText\">There&#8217;s tremendous value in isolating your bastion (Internet-accessible) hosts in a DMZ network, protected by a well-designed firewall and other external controls. And just as a good DMZ is designed assuming that sooner or later, even firewall-protected hosts may be compromised, good bastion server design dictates that each host should be hardened as though there were <span class=\"docEmphasis\">no<\/span> firewall at all.<\/p>\n<p class=\"docText\">Obviously, the bastion-host services to which your firewall allows access must be configured as securely as possible and kept up to date with security patches. But that isn&#8217;t enough: you must also secure the bastion host&#8217;s operating-system configuration and disable unnecessary servicesin short, &#8220;bastionize&#8221; or &#8220;harden&#8221; it as much as possible.<\/p>\n<p class=\"docText\">If you don&#8217;t do this, you won&#8217;t have a bastion server: you&#8217;ll simply have a server behind a firewallone that&#8217;s at the mercy of the firewall and the effectiveness of its own applications&#8217; security features. But if you do bastionize it, your server can defend itself should some other host in the DMZ be compromised and used to attack it. (As you can see, pessimism is an important element in risk management!)<\/p>\n<p class=\"docText\">Hardening a Linux system is not a trivial task: it&#8217;s as much work to bastionize Linux as Solaris, Windows, and other popular operating systems. This is a natural result of having so many different types of software available for these OSes, and at least as much variation between the types of people who use them.<\/p>\n<p class=\"docText\"><strong>OS Hardening Principles<\/strong><\/p>\n<p class=\"docText\">Operating-system hardening can be time consuming and even confusing. Like many OSes designed for a wide range of roles and user levels, Linux has historically tended to be &#8220;insecure by default&#8221;: most distributions&#8217; default installations are designed to present the user with as many preconfigured and active applications as possible. Therefore, securing a Linux system not only requires you to understand the inner workings of your system; you may also have to undo work others have done in the interest of shielding you from those inner workings!<\/p>\n<p class=\"docText\">Having said that, the principles of Linux hardening and OS hardening in general can be summed up by a single maxim: &#8220;That which is not explicitly permitted is forbidden.&#8221;\u00a0However, it scales very well to most other information security endeavors, including system hardening.<\/p>\n<p class=\"docText\">Another concept originally forged in a somewhat different context is the Principle of Least Privilege. This was originally used by the <a name=\"linuxss2-CHP-3-ITERM-2378\"><\/a>National Institute of Standards and Technology (NIST) to describe the desired behavior of the &#8220;Role-Based Access Controls&#8221; it developed for mainframe systems: &#8220;a user [should] be given no more privilege than necessary to perform a job&#8221; (<a class=\"docLink\" href=\"http:\/\/hissa.nist.gov\/rbac\/paper\/node5.html\" target=\"_blank\" rel=\"noopener\">http:\/\/hissa.nist.gov\/rbac\/paper\/node5.html<\/a>).<\/p>\n<p class=\"docText\">Nowadays people often extend the <a name=\"linuxss2-CHP-3-ITERM-2379\"><\/a><a name=\"linuxss2-CHP-3-ITERM-2380\"><\/a>Principle of Least Privilege to include applications; no application or process should have more privileges in the local operating environment than it needs to function. The Principle of Least Privilege and Ranum&#8217;s maxim sound like common sense (they <span class=\"docEmphasis\">are<\/span>, in my opinion). As they apply to system hardening, the real work stems from these corollaries:<\/p>\n<ul>\n<li>\n<p class=\"docList\">Install only necessary software; delete or disable everything else.<\/p>\n<\/li>\n<li>\n<p class=\"docList\">Keep all system and application software painstakingly up to date, at least with security patches, but preferably with <span class=\"docEmphasis\">all<\/span> package-by-package updates.<\/p>\n<\/li>\n<li>\n<p class=\"docList\">Delete or disable unnecessary user accounts.<\/p>\n<\/li>\n<li>\n<p class=\"docList\">Don&#8217;t needlessly grant shell access: <span class=\"docEmphasis\">\/bin\/false<\/span> should be the default shell for <span class=\"docEmphasis\">nobody<\/span>, <span class=\"docEmphasis\">guest<\/span>, and any other account used by services, rather than by an individual local user.<\/p>\n<\/li>\n<li>\n<p class=\"docList\">Allow each service (networked application) to be publicly accessible only by design, never by default.<\/p>\n<\/li>\n<li>\n<p class=\"docList\">Run each publicly accessible service in a <span class=\"docEmphasis\">chrooted<\/span> filesystem (i.e., a subset of <span class=\"docEmphasis\">\/<\/span>).<\/p>\n<\/li>\n<li>\n<p class=\"docList\">Don&#8217;t leave any executable file needlessly set to run with superuser privileges, i.e., with its <span class=\"docEmphasis\">SUID<\/span> bit set (unless owned by a sufficiently nonprivileged user).<\/p>\n<\/li>\n<li>\n<p class=\"docList\">In general, avoid using <i>root<\/i> privileges unnecessarily, and if your system has multiple administrators, delegate <span class=\"docEmphasis\">root<\/span>&#8216;s authority via <i>sudo<\/i>.<\/p>\n<\/li>\n<li>\n<p class=\"docList\">Configure logging and check logs regularly.<\/p>\n<\/li>\n<li>\n<p class=\"docList\">Configure every host as its own firewall; i.e., bastion hosts should have their <span class=\"docEmphasis\">own<\/span> packet filters and access controls in addition to (but <span class=\"docEmphasis\">not<\/span> instead of) the firewall&#8217;s.<\/p>\n<\/li>\n<li>\n<p class=\"docList\">Check your work now and then with a security scanner, especially after patches and upgrades.<\/p>\n<\/li>\n<li>\n<p class=\"docList\">Understand and use the security features supported by your operating system and applications, <span class=\"docEmphasis\">especially<\/span> when they add redundancy to your security fabric.<\/p>\n<\/li>\n<li>\n<p class=\"docList\">After hardening a bastion host, document its configuration so it may be used as a baseline for similar systems and so you can rebuild it quickly after a system compromise or failure.<\/p>\n<\/li>\n<\/ul>\n<p class=\"docText\">All of these corollaries are ways of implementing and enforcing the Principle of Least Privilege on a bastion host.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hardening Linux and Using iptables There&#8217;s tremendous value in isolating your bastion (Internet-accessible) hosts in a DMZ network, protected by a well-designed firewall and other external controls. And just as a good DMZ is designed assuming that sooner or later, even firewall-protected hosts may be compromised, good bastion server design<\/p>\n","protected":false},"author":3,"featured_media":875,"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_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[5],"tags":[],"class_list":["post-873","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-knowledgebase"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/02\/Linux_Server_Hardening.jpeg?fit=1170%2C822&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p7ISfL-e5","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":880,"url":"https:\/\/www.virtono.com\/community\/knowledgebase\/linux-securityfirewalls\/","url_meta":{"origin":873,"position":0},"title":"Linux Security:Firewalls","author":"Daniel Draga","date":"January 25, 2017","format":false,"excerpt":"Security is an important but complex topic. So I'll be doing a series of articles, focusing on the principles and working of security of Linux. The challenge is that it\u2019s an ever-changing idea. Software we think of as secure can become insecure as hackers figure out how to break though\u2026","rel":"","context":"In &quot;Knowledgebase&quot;","block_context":{"text":"Knowledgebase","link":"https:\/\/www.virtono.com\/community\/category\/knowledgebase\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/01\/firewall-hacker-720x380.jpg?fit=720%2C380&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/01\/firewall-hacker-720x380.jpg?fit=720%2C380&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/01\/firewall-hacker-720x380.jpg?fit=720%2C380&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/01\/firewall-hacker-720x380.jpg?fit=720%2C380&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":708,"url":"https:\/\/www.virtono.com\/community\/knowledgebase\/linux-hardening-securing-your-centos-6-server\/","url_meta":{"origin":873,"position":1},"title":"Linux Hardening : Securing your CentOS 6 server","author":"Daniel Draga","date":"October 18, 2016","format":false,"excerpt":"","rel":"","context":"In &quot;Knowledgebase&quot;","block_context":{"text":"Knowledgebase","link":"https:\/\/www.virtono.com\/community\/category\/knowledgebase\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2016\/10\/centos.jpg?fit=525%2C291&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2016\/10\/centos.jpg?fit=525%2C291&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2016\/10\/centos.jpg?fit=525%2C291&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":3191,"url":"https:\/\/www.virtono.com\/community\/tutorial-how-to\/how-to-install-postfix-on-linux\/","url_meta":{"origin":873,"position":2},"title":"How to install Postfix on Linux","author":"George B.","date":"April 8, 2023","format":false,"excerpt":"Install Postfix on CentOS 7 To install Postfix on CentOS 7, follow these steps: Open a terminal or login to your server via SSH as a root user. Update your system packages by running the following command: yum update Install Postfix using the following command: yum install postfix Start the\u2026","rel":"","context":"In &quot;Tutorials&quot;","block_context":{"text":"Tutorials","link":"https:\/\/www.virtono.com\/community\/category\/tutorial-how-to\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/04\/How-to-install-Postfix-on-Linux.png?fit=600%2C330&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/04\/How-to-install-Postfix-on-Linux.png?fit=600%2C330&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/04\/How-to-install-Postfix-on-Linux.png?fit=600%2C330&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":903,"url":"https:\/\/www.virtono.com\/community\/tutorial-how-to\/how-to-install-and-configure-csf-config-server-firewall-on-centos-7\/","url_meta":{"origin":873,"position":3},"title":"How to Install and Configure CSF (Config Server Firewall) on CentOS 7","author":"Daniel Draga","date":"April 11, 2017","format":false,"excerpt":"ConfigServe Firewall, also known as CSF, is a firewall configuration script created to provide better security for your server while giving you an easy to use, an advanced interface for managing your firewall settings. CSF configures your server\u2019s firewall to lock down public access to services and only allow certain\u2026","rel":"","context":"In &quot;Knowledgebase&quot;","block_context":{"text":"Knowledgebase","link":"https:\/\/www.virtono.com\/community\/category\/knowledgebase\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3947,"url":"https:\/\/www.virtono.com\/community\/tutorial-how-to\/how-to-install-configserver-security-firewall-csf-on-almalinux\/","url_meta":{"origin":873,"position":4},"title":"How to install ConfigServer Security &#038; Firewall -CSF on Almalinux","author":"George B.","date":"September 28, 2023","format":false,"excerpt":"In this guide, we will walk you through the step-by-step process of installing CSF on AlmaLinux, ensuring that your system is fortified against potential threats. Every system administrator has a responsibility to protect their server from potential attacks and vulnerabilities. ConfigServer Security & Firewall (CSF) is a strong tool that\u2026","rel":"","context":"In &quot;Tutorials&quot;","block_context":{"text":"Tutorials","link":"https:\/\/www.virtono.com\/community\/category\/tutorial-how-to\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/09\/How-to-install-CSF-on-Almalinux.png?fit=360%2C240&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":3930,"url":"https:\/\/www.virtono.com\/community\/tutorial-how-to\/how-to-install-apache-on-almalinux-9-2\/","url_meta":{"origin":873,"position":5},"title":"How to Install Apache on AlmaLinux 9.2","author":"George B.","date":"September 22, 2023","format":false,"excerpt":"This guide will walk you through setting up virtual hosts to run multiple websites on a single server and installing Apache on AlmaLinux 9.2. Whether you're running a personal blog, a small business website, or a complex web application, having a robust web server is essential. Apache, one of the\u2026","rel":"","context":"In &quot;Tutorials&quot;","block_context":{"text":"Tutorials","link":"https:\/\/www.virtono.com\/community\/category\/tutorial-how-to\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/09\/How-to-Install-Apache-on-AlmaLinux-9.2.png?fit=360%2C240&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/posts\/873","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/comments?post=873"}],"version-history":[{"count":2,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/posts\/873\/revisions"}],"predecessor-version":[{"id":877,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/posts\/873\/revisions\/877"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/media\/875"}],"wp:attachment":[{"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/media?parent=873"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/categories?post=873"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/tags?post=873"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}