{"id":1003,"date":"2019-01-27T22:10:29","date_gmt":"2019-01-27T12:10:29","guid":{"rendered":"https:\/\/www.airxperts.net\/?p=1003"},"modified":"2026-03-18T00:30:31","modified_gmt":"2026-03-17T14:30:31","slug":"troubleshooting-selinux-part-2","status":"publish","type":"post","link":"https:\/\/airxperts.net\/index.php\/2019\/01\/27\/troubleshooting-selinux-part-2\/","title":{"rendered":"Troubleshooting SELinux &#8211; Part 2"},"content":{"rendered":"<h4>Flashback<\/h4>\n\n\n<p>In <a href=\"https:\/\/www.airxperts.net\/index.php\/2018\/12\/30\/troubleshooting-selinux-part-1\/\">Part 1<\/a> of this series we gave a practical overview of <strong>S<\/strong>ecurity <strong>E<\/strong>nhanced <strong>Linux<\/strong> and a simplified explanation of the key terms and concepts.<\/p>\n\n\n\n<p>In this post we will learn how to the determine the status and and current mode of operation on a system, and how to change it.  Then we&#8217;ll touch on where and how SELinux logs information.<\/p>\n\n\n<h4>Checking the Status of SELinux<\/h4>\n<p>SELinux has two states <em>enabled<\/em> or <em>disabled<\/em>.<\/p>\n<p>The enabled state has two modes: <em>permissive<\/em> or <em>enforcing.<\/em><\/p>\n<p>In permissive mode SELinux is doing everything except denying any activity. Log messages will appear just as though SELinux was enforcing policy on your system.<\/p>\n<p>It is highly recommended to start in permissive mode and check your logs before going to enforcing, which we will do below. Permissive mode seems to be the default mode on most linux distros.<\/p>\n<p>The most useful commands for checkiong the status of SELinux are:<\/p>\n<pre>sestatus\ngetenforce<\/pre>\n<p>On Centos 7, these utilities can be found in the following packages which are part of the base installation:<\/p>\n<pre>[sysadmin@server ~]$ <strong>sudo yum -q whatprovides \/sbin\/sestatus<\/strong>\npolicycoreutils-2.5-29.el7.x86_64 : SELinux policy core utilities\nRepo : @base\n\n[sysadmin@server ~]$ <strong>sudo yum -q whatprovides \/sbin\/getenforce<\/strong>\nlibselinux-utils-2.5-14.1.el7.x86_64 : SELinux libselinux utilies\nRepo : @base\n<\/pre>\n<h5>SELinux Disabled<\/h5>\n<p>In disabled mode, SELinux is not loaded into the kernel, and no functionality is available.<\/p>\n<pre>[sysadmin@server ~]# <strong>sestatus<\/strong>\nSELinux status:                 disabled<\/pre>\n<p>If your machine looks like above, then check the following file:<\/p>\n<pre><strong>cat \/etc\/selinux\/config<\/strong>\n# This file controls the state of SELinux on the system.\n# SELINUX= can take one of these three values:\n# enforcing - SELinux security policy is enforced.\n# permissive - SELinux prints warnings instead of enforcing.\n# disabled - No SELinux policy is loaded.\nSELINUX=disabled\n# SELINUXTYPE= can take one of these two values:\n# targeted - Targeted processes are protected,\n# minimum - Modification of targeted policy. Only selected processes are protected.\n# mls - Multi Level Security protection.\nSELINUXTYPE=targeted<\/pre>\n<p>You will need to enable SELinux by changing &#8220;disabled&#8221; to &#8220;permissive&#8221; and then rebooting your machine.<\/p>\n<pre><strong>sudo vim \/etc\/selinux\/config<\/strong>\nSELINUX=permissive<\/pre>\n<p>This <em>should<\/em> be a safe action. I performed this without issue on a cloud machine on which I have no console access. The machine took a little longer to boot the first time, but came back as expected. Of course, there&#8217;s no guarantees so take care!<\/p>\n<h5>SELinux ENabled<\/h5>\n<p><em>getenforce<\/em> provides a simple one-line output, useful for confirming which enabled mode your system is in:<\/p>\n<pre>[sysadmin@server ~]$ <strong>getenforce<\/strong>\nPermissive<\/pre>\n<p><em>sestatus <\/em>provides a more detailed output:<\/p>\n<pre>[sysadmin@server ~]$ <strong>sestatus<\/strong>\nSELinux status: enabled\nSELinuxfs mount: \/sys\/fs\/selinux\nSELinux root directory: \/etc\/selinux\nLoaded policy name: targeted\nCurrent mode: permissive\nMode from config file: permissive\nPolicy MLS status: enabled\nPolicy deny_unknown status: allowed\nMax kernel policy version: 28<\/pre>\n<p>The most useful information here is the mode (permissive) and the policy name (targeted).<\/p>\n<p>From here we&#8217;ll assume you are in <em>permissive<\/em> mode.<\/p>\n<h4>How to find SELinux Logs<\/h4>\n<p>On Centos, SELinux uses the linux audit daemon (service), known as <em>auditd<\/em>.<\/p>\n<p>Auditd logs everything to \/var\/log\/audit\/audit.log which requires elevated privileges to read:<\/p>\n<pre>[sysadmin@server ~]$ <strong>less \/var\/log\/audit\/audit.log<\/strong>\nless: \/var\/log\/audit\/audit.log: Permission denied\n\n[sysadmin@server ~]$ <strong>sudo less \/var\/log\/audit\/audit.log<\/strong>\ntype=USER_AUTH msg=audit(1546124135.971:451246): pid=30238 uid=0 auid=4294967295 ses=4294967295 msg='op=PAM:authentication grantors=? acct=\"root\" exe=\"\/usr\/sbin\/sshd\" hostname=112.85.42.88 addr=112.85.42.88 terminal=ssh res=failed'\ntype=USER_AUTH msg=audit(1546124138.373:451247): pid=30238 uid=0 auid=4294967295 ses=4294967295 msg='op=password acct=\"root\" exe=\"\/usr\/sbin\/sshd\" hostname=? addr=112.85.42.88 terminal=ssh res=failed'\n&lt;...&gt;<\/pre>\n<p>On the plus side, everything you need is in one place. On the negative side, this file can get quite large, contains a log of messages unrelated to SELinux, and the output is a little cryptic.<\/p>\n<h5>Filtering Logs<\/h5>\n<p>As a first step we can just filter down to the relevant logs, which will contain the text &#8220;type=AVC&#8221;. Filtering on just &#8220;AVC&#8221; will also work:<\/p>\n<pre>[sysadmin@server ~]$ sudo grep \"AVC\" \/var\/log\/audit\/audit.log | less<\/pre>\n<p>AVC stands for <em>Access Vector Cache<\/em>. This is basically an in-memory cache of all SELinux decisions and is primarily used to improve performance. It also handles the logging of those decisions.<\/p>\n<p>On some of my systems there were no &#8220;AVC&#8221; entries in the audit file.\u00a0 On another, most of the entries were generated from activity on the internet-facing web server.<\/p>\n<p>I suggest running this command on some systems your administer and getting a feel for the number of messages being logged on each.<\/p>\n<h4>In Part 3&#8230;<\/h4>\n<p>In the next part we&#8217;ll get down in the weeds and troubleshoot some real world examples.<\/p>\n<p>In doing so we&#8217;ll start with basic Linux tools, and progress to using some of the more specific SELinux tools. These tools can interpret raw logs for us and even make usable recommendations on how to resolve issues.<\/p>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Flashback In Part 1 of this series we gave a practical overview of Security Enhanced Linux and a simplified explanation of the key terms and concepts. In this post we will learn how to the determine the status and and current mode of operation on a system, and how to change it. Then we&#8217;ll touch &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/airxperts.net\/index.php\/2019\/01\/27\/troubleshooting-selinux-part-2\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Troubleshooting SELinux &#8211; Part 2&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":983,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48],"tags":[51,49,52,50],"class_list":["post-1003","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sysadmin","tag-centos","tag-linux","tag-security","tag-selinux"],"_links":{"self":[{"href":"https:\/\/airxperts.net\/index.php\/wp-json\/wp\/v2\/posts\/1003","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/airxperts.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/airxperts.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/airxperts.net\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/airxperts.net\/index.php\/wp-json\/wp\/v2\/comments?post=1003"}],"version-history":[{"count":9,"href":"https:\/\/airxperts.net\/index.php\/wp-json\/wp\/v2\/posts\/1003\/revisions"}],"predecessor-version":[{"id":1032,"href":"https:\/\/airxperts.net\/index.php\/wp-json\/wp\/v2\/posts\/1003\/revisions\/1032"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/airxperts.net\/index.php\/wp-json\/wp\/v2\/media\/983"}],"wp:attachment":[{"href":"https:\/\/airxperts.net\/index.php\/wp-json\/wp\/v2\/media?parent=1003"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/airxperts.net\/index.php\/wp-json\/wp\/v2\/categories?post=1003"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/airxperts.net\/index.php\/wp-json\/wp\/v2\/tags?post=1003"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}