Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
linux_config_selinux [2020/09/29 10:16] – created andonovj | linux_config_selinux [2021/05/18 15:07] (current) – [Overview] andonovj | ||
---|---|---|---|
Line 1: | Line 1: | ||
=====Overview===== | =====Overview===== | ||
- | SElinux or Security Enchanced linux is PAIN in the " | + | SElinux or Security Enchanced linux is PAIN in the " |
So let's see how to disable and check for status: | So let's see how to disable and check for status: | ||
Line 54: | Line 54: | ||
</ | </ | ||
+ | ====Modift SELinux Context==== | ||
+ | SElinux operates in contexts. But before we start checking the context of files and directories, | ||
+ | |||
+ | < | ||
+ | [root@tbp-mts-redis01 data]# yum install -y policycoreutils-python-utils | ||
+ | Last metadata expiration check: 0:27:48 ago on Tue 29 Sep 2020 11:30:40 CEST. | ||
+ | Dependencies resolved. | ||
+ | =========================================================================================================================================================================================== | ||
+ | | ||
+ | =========================================================================================================================================================================================== | ||
+ | Installing: | ||
+ | | ||
+ | Installing dependencies: | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | Transaction Summary | ||
+ | =========================================================================================================================================================================================== | ||
+ | Install | ||
+ | |||
+ | Total download size: 3.6 M | ||
+ | Installed size: 11 M | ||
+ | Downloading Packages: | ||
+ | (1/6): python3-audit-3.0-0.17.20191104git1c2f876.el8.x86_64.rpm | ||
+ | (2/6): policycoreutils-python-utils-2.9-9.el8.noarch.rpm | ||
+ | (3/6): python3-libsemanage-2.9-2.el8.x86_64.rpm | ||
+ | (4/6): checkpolicy-2.9-1.el8.x86_64.rpm | ||
+ | (5/6): python3-setools-4.2.2-2.el8.x86_64.rpm | ||
+ | (6/6): python3-policycoreutils-2.9-9.el8.noarch.rpm | ||
+ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
+ | Total 304 kB/s | 3.6 MB 00:12 | ||
+ | Running transaction check | ||
+ | Transaction check succeeded. | ||
+ | Running transaction test | ||
+ | Transaction test succeeded. | ||
+ | Running transaction | ||
+ | Preparing | ||
+ | Installing | ||
+ | Installing | ||
+ | Installing | ||
+ | Installing | ||
+ | Installing | ||
+ | Installing | ||
+ | Running scriptlet: policycoreutils-python-utils-2.9-9.el8.noarch | ||
+ | Verifying | ||
+ | Verifying | ||
+ | Verifying | ||
+ | Verifying | ||
+ | Verifying | ||
+ | Verifying | ||
+ | |||
+ | Installed: | ||
+ | checkpolicy-2.9-1.el8.x86_64 | ||
+ | python3-policycoreutils-2.9-9.el8.noarch | ||
+ | |||
+ | Complete! | ||
+ | </ | ||
+ | |||
+ | That will give us the " | ||
+ | Now there are 2 ways to manage the contaxt of a file or directory: | ||
+ | |||
+ | - Use chcon - temporary | ||
+ | - Use semanage & restorecon - permanent | ||
+ | |||
+ | So let's try it. Firstly we check the context as follows: | ||
+ | |||
+ | < | ||
+ | ~]# ls -dZ /web | ||
+ | drwxr-xr-x | ||
+ | </ | ||
+ | |||
+ | In this example, the SELinux context for file1 includes the SELinux unconfined_u user, object_r role, user_home_t type, and the s0 level. For a description of each part of the SELinux context [[https:// | ||
+ | |||
+ | ====Change the context temporary==== | ||
+ | To change it temporary we can use the following command: | ||
+ | |||
+ | < | ||
+ | ~]# ls -dZ /web | ||
+ | drwxr-xr-x | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | ~]# chcon -R -t httpd_sys_content_t /web/ | ||
+ | ~]# ls -dZ /web/ | ||
+ | drwxr-xr-x | ||
+ | </ | ||
+ | |||
+ | Again, that is not a permanent change so we can restore it with restart OR using restorecon: | ||
+ | |||
+ | < | ||
+ | ~]$ restorecon -v file1 | ||
+ | restorecon reset file1 context unconfined_u: | ||
+ | </ | ||
+ | |||
+ | ====Change the context permanent==== | ||
+ | To change the context permanently we have to use the " | ||
+ | |||
+ | < | ||
+ | ~]# ls -dZ /web | ||
+ | drwxr-xr-x | ||
+ | ~]# semanage fcontext -a -t httpd_sys_content_t "/ | ||
+ | ~]# restorecon -R -v /web | ||
+ | ~]$ ls -dZ /web | ||
+ | drwxr-xr-x | ||
+ | </ | ||