SELinux


selinux - NSA Security-Enhanced Linux (SELinux)

SELinux工作在內核當中,偽目錄 /selinux/,進程工作在SELinux中,就好比工作在沙箱當中,進程能訪問那些文件,權限由SELinux規則決定,SELinux的目的就是讓進程擁有最小化權限。

1、啟用或關閉selinux

查看當前是否啟用:

[root@myhost01 tmp]# getenforce
Disabled

狀態:

Enforcing:啟用狀態,當進程訪問了沒有權限訪問的文件時會被禁止並記錄到日志,/var/log/audit/audit.log。

Permissive:工作在正常狀態下,當進程訪問了沒有權限訪問的文件,不會被禁止,僅僅記錄到日志。

Disabled:永久關閉selinux,/etc/sysconfig/selinux,SELINUX=disabled,改完之后重啟系統才會生效。

setenforce 0:臨時關閉selinux對操作的影響,實際上修改的是/selinux/enforce文件,所以也可以echo 0 > /selinux/enforce進行關閉。

2、對文件進行修改類型,上下文  Labeling files

ls -Z 可以看到文件的SELinux屬性,分別是user,role,type文件類型

創建/tmp/selinux.txt,修改SELinux類型為var_log_t

chcon:chcon - change file SELinux security context

-t, --type=TYPE
              set type TYPE in the target security context
-R, --recursive,遞歸目錄
              operate on files and directories recursively
--reference=RFILE
              use RFILE’s security context rather than specifying a CONTEXT value

 

[root@myhost01 tmp]# ls -Z
-rw-r--r-- root root ?                                selinux.txt
[root@myhost01 tmp]# chcon --reference=/var/log/anaconda.log /tmp/selinux.txt
[root@myhost01 tmp]# ls -Z /tmp/
-rw-r--r--. root root system_u:object_r:var_log_t:s0   selinux.txt
[root@myhost01 tmp]# chcon -t consolekit_log_t  /tmp/selinux.txt
[root@myhost01 tmp]# ls -Z /tmp/
-rw-r--r--. root root system_u:object_r:consolekit_log_t:s0 selinux.txt
[root@myhost01 tmp]#

context被改亂了,可以恢復默認

restorecon - restore file(s) default SELinux security contexts.

 

restorecon filename


selinux運行時修改bool開關

getsebool -a 查看

samba正常工作

setsebool samba_enable_home_dirs=0或off    1或on

 

3、semanage

semanage fcontext -l 列出在哪些目錄下創建文件的默認類型。

semanage user -l 列出建立的selinux用戶

semanage port -l 列出受selinux控制的端口

加入受管理端口:semanage port -a -t http_port_t -p tcp 8989
 


 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM