selinux是什么
安全增强型linux(selinux)是一个linux内核的功能,它提供支持访问控制的安全政策保护机制。
开启selinux
1.以root权限远程连接linux
2.编辑selinux的config文件。
vim /etc/selinux/config
3.找到selinux=disabled
,按i进入编辑模式,通过修改该参数开启selinux。
可以根据需求修改参数,开启selinux有以下两种模式:
- 强制模式selinux=enforcing:表示所有违反安全策略的行为都将被禁止。
- 宽容模式selinux=permissive:表示所有违反安全策略的行为不被禁止,但是会在日志中作记录。
4.修改完成后,按下键盘esc键,执行命令:wq,保存并退出文件。
5.在根目录下新建隐藏文件autorelabel,实例重启后,selinux会自动重新标记所有系统文件。
touch /.autorelabel
6.重启linux
shutdown -r now
验证selinux状态
1.以root权限远程连接ecs实例。连接方式请参见连接方式概述。运行命令getenforce,验证selinux状态。
2.返回状态应为enforcing或者permissive,本教程当前状态为enforcing。
3.运行命令sestatus,获取更多selinux信息。
参数信息selinux status显示为enabled,表示selinux已启动。
关闭selinux
1.以root权限远程连接ecs实例。连接方式请参见连接方式概述。
2.运行命令getenforce,验证selinux状态。返回状态如果是enforcing,表明selinux已开启。
3.选择临时关闭或者永久关闭selinux。
- 执行命令setenforce 0临时关闭selinux。
- 永久关闭selinux。
a.运行以下命令,编辑selinux的config文件。vim /etc/selinux/config
b.找到selinux=enforcing,按i进入编辑模式,将参数修改为selinux=disabled。
[root@ncayu101 data]# getenforce enforcing # 临时关闭 selinux [root@ncayu101 data]# setenforce 0 [root@ncayu101 data]# [root@ncayu101 data]# [root@ncayu101 data]# getenforce permissive
# 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 values: # targeted - targeted processes are protected, # minimum - modification of targeted policy. only selected processes are protected. # mls - multi level security protection. selinuxtype=targeted
我已经修改好了
- 修改完成后,按下键盘esc键,执行命令:wq,保存并退出文件。
- 运行命令getenforce,验证selinux状态为disabled,表明selinux已关闭。
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论