Difference between revisions of "SELinux Notes"
From Simson Garfinkel
Jump to navigationJump to search
m |
|||
Line 24: | Line 24: | ||
# You can give the web server read/write access to the files with: | # You can give the web server read/write access to the files with: | ||
chcon -R -t httpd_sys_rw_content_t /var/www/html/xxx | chcon -R -t httpd_sys_rw_content_t /var/www/html/xxx | ||
== CGI scripts under SELinux == | |||
You can see the selinux policy for cgi-bin with: | |||
$ semanage fcontext --list | grep cgi-bin | |||
You can give the script the SELinux context with: | |||
$ chcon -t httpd_sys_script_exec_t /var/www/html/script.cgi | |||
Check the file's SELinux attributes with `ls -laZ`: | |||
$ ls -laZ /var/www/html/script.cgi | |||
References: | |||
* https://serverfault.com/questions/691501/apache-permission-denied-exec-of-var-www-html-cgi-test-first-pl-failed | |||
== Disabling SELinux == | == Disabling SELinux == | ||
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Security-Enhanced_Linux/sect-Security-Enhanced_Linux-Working_with_SELinux-Changing_SELinux_Modes.html#sect-Security-Enhanced_Linux-Enabling_and_Disabling_SELinux-Permissive_Mode | * https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Security-Enhanced_Linux/sect-Security-Enhanced_Linux-Working_with_SELinux-Changing_SELinux_Modes.html#sect-Security-Enhanced_Linux-Enabling_and_Disabling_SELinux-Permissive_Mode | ||
* edit /etc/selinux/config and change SELINUX from 'enforcing' to 'permissive' | * edit /etc/selinux/config and change SELINUX from 'enforcing' to 'permissive' |
Revision as of 19:51, 19 March 2019
SELinux is enabled by default on Centos 7 and on RHEL. It's a good thing to enable for internet-facing servers. It makes it far, far more complex to run a web server.
References:
- https://wiki.centos.org/HowTos/SELinux
- https://wiki.gentoo.org/wiki/SELinux/Tutorials/What_is_this_unconfined_thingie_and_tell_me_about_attributes
- https://stackoverflow.com/questions/5326531/php-warning-unknown-failed-to-open-stream
- https://wiki.centos.org/HowTos/SELinux
- https://www.lisenet.com/2016/advanced-apache-configuration-with-selinux-on-rhel-7/
Problem: apache can't access the files
sudo /sbin/restorecon -R /var/www
setsebool -P httpd_read_user_content 1
Running a web server:
If you can't run PHP, you may have the files in the wrong SELinux security context. You can change the security
- Use ls -lZ /var/www/html/xxx to check the security context
- You can give the web server read/write access to the files with:
chcon -R -t httpd_sys_rw_content_t /var/www/html/xxx
CGI scripts under SELinux
You can see the selinux policy for cgi-bin with:
$ semanage fcontext --list | grep cgi-bin
You can give the script the SELinux context with:
$ chcon -t httpd_sys_script_exec_t /var/www/html/script.cgi
Check the file's SELinux attributes with `ls -laZ`:
$ ls -laZ /var/www/html/script.cgi
References:
Disabling SELinux
- edit /etc/selinux/config and change SELINUX from 'enforcing' to 'permissive'