Linux下开启关闭SeLinux
2015-07-08 22:01
615 查看
SELinux(Security-EnhancedLinux)inFedoraisanimplementationofmandatoryaccesscontrolintheLinuxkernelusingtheLinuxSecurityModules(LSM)framework.StandardLinuxsecurityisadiscretionaryaccesscontrolmodel.Discretionaryaccesscontrol(DAC)DACisstandardLinuxsecurity,anditprovidesminimalprotectionfrombrokensoftwareormalwarerunningasanormaluserorroot.Userscangrantriskylevelsofaccesstofilestheyown.Mandatoryaccesscontrol(MAC)MACprovidesfullcontroloverallinteractionsofsoftware.Administrativelydefinedpolicycloselycontrolsuserandprocessinteractionswiththesystem,andcanprovideprotectionfrombrokensoftwareormalwarerunningasanyuser.目前SELinux支持三种模式,分别如下:enforcing:强制模式,代表SELinux运作中,且已经正确的开始限制domain/type了;permissive:宽容模式:代表SELinux运作中,不过仅会有警告讯息并不会实际限制domain/type的存取。这种模式可以用来作为SELinux的debug之用;disabled:关闭,SELinux并没有实际运作在Linux下查看是否开启了SeLinux,可以用下面两种方法1:可以使用下面命令sestatus,SELinuxstatus为enabled表示开启了SeLinux功能
2:使用命令getenforce
如何开启、关闭SeLinux呢?最简单的方式使用setenforce,这样不用重启服务器.但是该命令只能将SeLinux在enforcing、permissive这两种模式之间切换.服务器重启后,又会恢复到/etc/selinux/config下,也就是说setenforce的修改是不能持久的。
另外就是修改/etc/selinux/config,如下所示,可以配置SELINUX为enforcing、permissive、disabled三个值,修改后必须重启系统才能生效
如果由enforcing或permissive改成disabled,或由disabled改成其他两个,那也必须要重新开机。这是因为SELinux是整合到核心里面去的,你只可以在SELinux运作下切换成为强制(enforcing)或宽容(permissive)模式,不能够直接关闭SELinux的!同时,由SELinux关闭(disable)的状态到开启的状态也需要重新开机啦!
[root@DB-Server~]#/usr/sbin/sestatus
SELinuxstatus:enabled
SELinuxfsmount:/selinux
Currentmode:enforcing
Modefromconfigfile:enforcing
Policyversion:21
Policyfromconfigfile:targeted
[root@DB-Server~]#
[root@DB-Server~]#/usr/sbin/sestatus-v
SELinuxstatus:enabled
SELinuxfsmount:/selinux
Currentmode:enforcing
Modefromconfigfile:enforcing
Policyversion:21
Policyfromconfigfile:targeted
Processcontexts:
Currentcontext:root:system_r:unconfined_t:SystemLow-SystemHigh
Initcontext:system_u:system_r:init_t
/sbin/mingettysystem_u:system_r:getty_t
/usr/sbin/sshdsystem_u:system_r:unconfined_t:SystemLow-SystemHigh
Filecontexts:
Controllingterm:root:object_r:devpts_t
/etc/passwdsystem_u:object_r:etc_t
/etc/shadowsystem_u:object_r:shadow_t
/bin/bashsystem_u:object_r:shell_exec_t
/bin/loginsystem_u:object_r:login_exec_t
/bin/shsystem_u:object_r:bin_t->system_u:object_r:shell_exec_t
/sbin/agettysystem_u:object_r:getty_exec_t
/sbin/initsystem_u:object_r:init_exec_t
/sbin/mingettysystem_u:object_r:getty_exec_t
/usr/sbin/sshdsystem_u:object_r:sshd_exec_t
/lib/libc.so.6system_u:object_r:lib_t->system_u:object_r:lib_t
/lib/ld-linux.so.2system_u:object_r:lib_t->system_u:object_r:ld_so_t
Youhavenewmailin/var/spool/mail/root
[root@DB-Server~]#
2:使用命令getenforce
[root@DB-Server~]#getenforce
Enforcing
如何开启、关闭SeLinux呢?最简单的方式使用setenforce,这样不用重启服务器.但是该命令只能将SeLinux在enforcing、permissive这两种模式之间切换.服务器重启后,又会恢复到/etc/selinux/config下,也就是说setenforce的修改是不能持久的。
[root@DB-Server~]#setenforce0
[root@DB-Server~]#getenforce
Permissive
[root@DB-Server~]#setenforce1
[root@DB-Server~]#getenforce;
Enforcing
[root@DB-Server~]#
另外就是修改/etc/selinux/config,如下所示,可以配置SELINUX为enforcing、permissive、disabled三个值,修改后必须重启系统才能生效
[root@DB-Server~]#more/etc/selinux/config
#ThisfilecontrolsthestateofSELinuxonthesystem.
#SELINUX=cantakeoneofthesethreevalues:
#enforcing-SELinuxsecuritypolicyisenforced.
#permissive-SELinuxprintswarningsinsteadofenforcing.
#disabled-SELinuxisfullydisabled.
SELINUX=enforcing
#SELINUXTYPE=typeofpolicyinuse.Possiblevaluesare:
#targeted-Onlytargetednetworkdaemonsareprotected.
#strict-FullSELinuxprotection.
SELINUXTYPE=targeted
Youhavenewmailin/var/spool/mail/root
[root@DB-Server~]#
如果由enforcing或permissive改成disabled,或由disabled改成其他两个,那也必须要重新开机。这是因为SELinux是整合到核心里面去的,你只可以在SELinux运作下切换成为强制(enforcing)或宽容(permissive)模式,不能够直接关闭SELinux的!同时,由SELinux关闭(disable)的状态到开启的状态也需要重新开机啦!
相关文章推荐
- 在 Linux 中配置 SFTP 环境
- linux快速生成大文件方法
- linux下使用命令修改IP地址
- linux下使用命令修改IP地址
- U盘安装centos 7 提示 “Warning: /dev/root does not exist, could not boot” 解决办法
- centos6.3 安装python2.7.3
- linux块设备驱动之相关结构体间的关系
- linux程序设计——进程管道(第十三章)
- Linux的内存管理机制
- centos7 安装 gflags 出现config.status: error: cannot find input file: src/Makefile.in
- linux程序设计——多线程小结以及待完成的小游戏(第十二章)
- centos下yum安装lamp和lnmp轻松搞定
- Linux下git学习笔记(一)
- Linux挂载windows共享目录
- Linux中的权限以及访问控制
- Linux中的权限以及访问控制
- HAproxy+keepalived+mysql高可用性Linux系统集群
- Linux软件源码编译安装
- Linux五种IO模型性能分析
- Linux命令之文件与目录的权限