共 1 篇文章

标签:CentOS7.4安装使用SELinux防护系统的简要说明 (centos7.4 selinux)

CentOS7.4安装使用SELinux防护系统的简要说明 (centos7.4 selinux)

SELinux是安全增强型Linux(Security Enhanced Linux)的缩写,是一种在Linux操作系统中实现Mandatory access control(MAC,强制性访问控制)的机制,能够有效地防止未授权的访问和访问的结果。在CentOS7.4发行版中,SELinux已经默认安装并开启,但是由于其较为复杂的配置和使用,导致很多用户不知道如何使用SELinux防护自己的系统,本文将简要说明CentOS7.4安装使用SELinux防护系统的方法。 一、SELinux的安装 由于CentOS7.4默认安装了SELinux,所以无需再次安装。如果要安装其他版本的SELinux,可以使用yum命令进行安装: yum install selinux-policy 二、SELinux的开关 在CentOS7.4中,SELinux默认开启。可以使用以下命令检查SELinux的状态: sestatus 若显示如下信息,则表示SELinux处于enforcing状态: SELinux status: enabled SELinuxfs mount: /sys/fs/selinux SELinux root directory: /etc/selinux Loaded policy name: targeted Current mode: enforcing Mode from config file: enforcing Policy MLS status: enabled Policy deny_unknown status: allowed Max kernel policy version: 31 如果需要关闭SELinux,可以使用以下命令: setenforce 0 如果需要重新打开SELinux,可以使用以下命令: setenforce 1 三、SELinux的配置 1.用selinuxconfig工具修改SELinux配置文件 SELinux的配置文件位于/etc/selinux/config中。可以使用selinuxconfig工具修改此文件的内容: sudo selinuxconfig 在弹出的配置窗口中,可以选择SELinux的三种模式:Enforcing(强制模式)、Permissive(宽容模式)和Disable(关闭模式)。 Enforcing模式:在该模式下,SELinux是启用的,对系统的访问进行强制限制,不符合规则的访问行为将被阻止。 Permissive模式:在该模式下,SELinux处于宽容模式,只会发出警告消息,不会阻止访问行为。 Disable模式:在该模式下,SELinux处于关闭状态,和传统的Linux系统一样工作。 2.手动编辑SELinux配置文件 可以手动编辑SELinux配置文件/etc/selinux/config进行配置。 SELINUX=enforcing # SELinux默认开启,可以改为permissive或disabled进行设置 SELINUXTYPE=targeted # SELinux策略类型,目前有targeted和mls两种 SETLOCALDEFS=0 # 是否允许修改本地定义,一般为0 四、SELinux的使用 1.安装auditd,用于监测系统日志 在CentOS7.4中,auditd是SELinux的默认日志记录工具,可以使用以下命令进行安装: yum install audit 安装完成后,需要启动auditd服务: systemctl start auditd 2.添加SELinux策略 使用audit2allow工具来添加SELinux策略。audit2allow可以根据系统日志中的记录生成一些被SELinux拒绝的操作,并将这些操作转换为SELinux策略。 如下示例,在CentOS7.4中安装了Nginx服务,在启动Nginx时,SELinux会拒绝访问端口80号: [root@localhost ~]# systemctl start nginx Job for nginx.service fled because the control process exited with error code. See “systemctl status nginx.service” and “journalctl -xe” for detls. [root@localhost ~]# systemctl status nginx.service nginx.service...

技术分享