以下为你带来新手配置SELinux基础教程:配置和生成SELinux man页面。在默认情况下,RHEL 7或CentOS 7系统中都没有安装SELinux策略的SELinux man页面,必须自己安装必要的工具并生成手册页。本文将向你介绍配置SELinux环境和添加手册页,以便于更好的参考或排除SELinux故障。
启用SELinux
如果要检查SELinux是否正在运行,请在终端上输入以下命令:
[root@server1 ~]# getenforce
Enforcing
从上面的输出中,你可以看到SELinux正在运行并强制执行所有策略规则,我通过编辑/etc/selinux/config永久设置selinux:
[root@server1 ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
设置SELINUX=enforcing行。
如果要在不手动编辑文件的情况下永久启用SELinux,只需以root用户身份打开终端窗口,然后输入以下命令:
[root@server1 ~]# sed -i 's/SELINUX=disabled/SELINUX=enforcing/' /etc/selinux/config
你可以通过输入以下命令在下次启动时启用自动重新标记:
[root@server1 ~]# touch /.autorelabel
然后重新启动系统以使更改生效:
[root@server1 ~]# reboot
成功重启后,检查SELlinux的状态,它应该以强制模式运行的:
[root@server1 ~]# getenforce
Enforcing
安装必要的SELinux软件包
由于SELinux现在能够实施策略规则,因此我们可以安装有助于我们有效管理selinux的软件包。
1、安装setroubleshoot-server软件包。
1]、该软件包提供了帮助诊断SELinux问题的工具。
2]、生成AVC消息时,可以生成警报,提供有关问题的信息并帮助跟踪其解决方案。
3]、要安装它,请输入以下命令:
[root@server1 ~]# yum install setroubleshoot-server -y
2、policycoreutils-python包中包含用于管理SELinux环境的管理工具。
如果安装了setroubleshoot-server,它会将policycoreutils-python作为依赖项安装,因此如果安装了setroubleshoot-server软件包,则可以跳过此步骤:
[root@server1 ~]# yum install policycoreutils-python
3、另一个要安装的软件包是policycoreutils-devel
1]、Policycoreutils-devel软件包包含用于在SELinux环境中开发策略的管理工具。
2]、这个包帮助我们生成selinux man页面。
3]、可以查看提供sepolicy的内容,它实际上是由policycoreutils-devel包提供的SELinux man页生成实用程序:
[root@server1 ~]# yum provides */sepolicy
[root@server1 ~]# yum install policycoreutils-devel
现在已经拥有所有必需的包,现在就生成SELinux man页面。
生成SELinux man页面
命令sepolicy manpage用于根据安装的SELinux策略生成手册页(man pages)。
常用选项有:
-a,-all Generate Man Pages for All Domains(为所有域生成手册页)
-d,-domain Generate a Man Page for the specified domain. (Supports multiple commands)(为指定的域生成手册页,支持多个命令)
-h,-help Display help message(显示帮助信息)
-p,-path Specify the directory to store the created man pages. (Default to /tmp)(指定存储创建的手册页的目录,默认为/tmp)
-r,-root Specify alternate root directory to generate man pages from. (Default to /)(指定备用根目录以生成手册页,默认为/)
-w,-web Generate an additional HTML man pages for the specified domain(s)(为指定的域生成其他HTML手册页)
输入以下命令生成selinux man页面:
[root@server1 ~]# sepolicy manpage -a -p /usr/share/man/man8/
从上面使用的选项,告诉sepolicy手册页为所有域生成手册页,存储手册页的路径是/usr/share/man/man8/。
在生成手册页之后,现在是时候更新手册页数据库,以便我们可以使用sepolicy手册页命令生成的手册页。
你现在可以更新手册页数据库,我们将使用命令mandb,它用于初始化或手动更新通常由man维护的索引数据库缓存:
[root@server1 ~]# mandb
如果你现在搜索所有selinux手册页,将获得一个很长的列表,请通过输入以下命令自行尝试:
[root@server1 ~]# man -k _selinux
要稍微删除搜索,将输出传递给grep命令(在Linux系统下使用grep命令搜索文件的详细用法),请查看下面的示例:
man -k _selinux | grep httpd>搜索selinux httpd相关的手册页。
man -k _selinux | egrep ‘samba|smb’>搜索与samba相关的selinux手册页。
man -k _selinux | egrep *nfs>搜索nfs守护程序相关的selinux手册页。
使用grep获取所需的SELinux man页是很容易的事情:
[root@server1 ~]# man -k _selinux | grep httpd
apache_selinux (8) - Security Enhanced Linux Policy for the httpd processes
httpd_helper_selinux (8) - Security Enhanced Linux Policy for the httpd_helper processes
httpd_passwd_selinux (8) - Security Enhanced Linux Policy for the httpd_passwd processes
httpd_php_selinux (8) - Security Enhanced Linux Policy for the httpd_php processes
httpd_rotatelogs_selinux (8) - Security Enhanced Linux Policy for the httpd_rotatelogs processes
httpd_selinux (8) - Security Enhanced Linux Policy for the httpd processes
httpd_suexec_selinux (8) - Security Enhanced Linux Policy for the httpd_suexec processes
httpd_sys_script_selinux (8) - Security Enhanced Linux Policy for the httpd_sys_script processes
httpd_unconfined_script_selinux (8) - Security Enhanced Linux Policy for the httpd_unconfined_script processes
httpd_user_script_selinux (8) - Security Enhanced Linux Policy for the httpd_user_script processes
至此,本文的目的达到。
相关主题