在CentOS系统中,查看SELinux(Security-Enhanced Linux)的上下文(context)设置可以通过以下几种方法:
ls -Z
命令ls -Z
命令可以显示文件和目录的安全上下文。
ls -Z /path/to/directory_or_file
例如:
ls -Z /etc/passwd
输出示例:
-rw-r--r--. root root system_u:object_r:etc_t:s0 /etc/passwd
这里的system_u:object_r:etc_t:s0
就是文件的安全上下文。
getfattr
命令getfattr
命令可以显示文件的扩展属性,包括SELinux上下文。
getfattr -n security.selinux /path/to/directory_or_file
例如:
getfattr -n security.selinux /etc/passwd
输出示例:
# file: /etc/passwd
# owner: root
# group: root
user.security.selinux=system_u:object_r:etc_t:s0
semanage fcontext
命令semanage fcontext
命令可以查看和管理文件系统上下文。
semanage fcontext -l | grep /path/to/directory_or_file
例如:
semanage fcontext -l | grep /etc/passwd
输出示例:
/etc/passwd system_u:object_r:etc_t:s0
SELinux策略文件通常位于/etc/selinux/
目录下,例如/etc/selinux/targeted/policy/policies/
。你可以查看这些文件来了解SELinux上下文的定义。
cat /etc/selinux/targeted/policy/policies/policy.31
seinfo
命令seinfo
命令可以显示SELinux策略中的所有信息,包括上下文。
seinfo -A | grep /path/to/directory_or_file
例如:
seinfo -A | grep /etc/passwd
输出示例:
/etc/passwd system_u:object_r:etc_t:s0 file /etc/passwd
通过以上方法,你可以方便地查看CentOS系统中文件和目录的SELinux上下文设置。