Linux下开启关闭SeLinux

SELinux (Security-Enhanced Linux) in Fedora is an implementation of mandatory access control in the Linux kernel using the Linux Security Modules (LSM) framework. Standard Linux security is a discretionary access control model.

Discretionary access control (DAC)

DAC is standard Linux security, and it provides minimal protection from broken software or malware running as a normal user or root. Users can grant risky levels of access to files they own.

Mandatory access control (MAC)

MAC provides full control over all interactions of software. Administratively defined policy closely controls user and process interactions with the system, and can provide protection from broken software or malware running as any user.

目前 SELinux 支持三种模式,分别如下:

enforcing :强制模式,代表 SELinux 运作中,且已经正确的开始限制 domain/type 了;

permissive:宽容模式:代表 SELinux 运作中,不过仅会有警告讯息并不会实际限制 domain/type 的存取。这种模式可以

用来作为 SELinux 的 debug 之用;

disabled :关闭,SELinux 并没有实际运作

在Linux下查看是否开启了SeLinux,可以用下面两种方法

1: 可以使用下面命令sestatus,SELinux status 为enabled表示开启了SeLinux功能

[[email protected] ~]# /usr/sbin/sestatus
SELinux status:                 enabled

SELinuxfs mount:                /selinux

Current mode:                   enforcing

Mode from config file:          enforcing

Policy version:                 21

Policy from config file:        targeted

[[email protected] ~]# 

 

 

 

[[email protected] ~]# /usr/sbin/sestatus -v

SELinux status:                 enabled

SELinuxfs mount:                /selinux

Current mode:                   enforcing

Mode from config file:          enforcing

Policy version:                 21

Policy from config file:        targeted

 

Process contexts:

Current context:                root:system_r:unconfined_t:SystemLow-SystemHigh

Init context:                   system_u:system_r:init_t

/sbin/mingetty                  system_u:system_r:getty_t

/usr/sbin/sshd                  system_u:system_r:unconfined_t:SystemLow-SystemHigh

 

File contexts:

Controlling term:               root:object_r:devpts_t

/etc/passwd                     system_u:object_r:etc_t

/etc/shadow                     system_u:object_r:shadow_t

/bin/bash                       system_u:object_r:shell_exec_t

/bin/login                      system_u:object_r:login_exec_t

/bin/sh                         system_u:object_r:bin_t -> system_u:object_r:shell_exec_t

/sbin/agetty                    system_u:object_r:getty_exec_t

/sbin/init                      system_u:object_r:init_exec_t

/sbin/mingetty                  system_u:object_r:getty_exec_t

/usr/sbin/sshd                  system_u:object_r:sshd_exec_t

/lib/libc.so.6                  system_u:object_r:lib_t -> system_u:object_r:lib_t

/lib/ld-linux.so.2              system_u:object_r:lib_t -> system_u:object_r:ld_so_t

You have new mail in /var/spool/mail/root

[[email protected] ~]# 

2:使用命令getenforce

[[email protected] ~]# getenforce
 

Enforcing

如何开启、关闭SeLinux呢?最简单的方式使用setenforce,这样不用重启服务器. 但是该命令只能将SeLinux在enforcing、permissive这两种模式之间切换.服务器重启后,又会恢复到/etc/selinux/config 下,也就是说setenforce的修改是不能持久的。

[[email protected] ~]# setenforce 0
 

[[email protected] ~]# getenforce

 

Permissive

 

[[email protected] ~]# setenforce 1

 

[[email protected] ~]# getenforce;

 

Enforcing

 

[[email protected] ~]# 

另外就是修改/etc/selinux/config ,如下所示,可以配置SELINUX为enforcing、permissive、disabled三个值,修改后必须重启系统才能生效

[[email protected] ~]# more /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 - SELinux is fully disabled.

SELINUX=enforcing

# SELINUXTYPE= type of policy in use. Possible values are:

#       targeted - Only targeted network daemons are protected.

#       strict - Full SELinux protection.

SELINUXTYPE=targeted

You have new mail in /var/spool/mail/root

[[email protected] ~]# 

如果由 enforcing 或 permissive 改成 disabled ,或由 disabled 改成其他两个,那也必须要重新开机。这是因为 SELinux 是整合到核心里面去的, 你只可以在SELinux 运作下切换成为强制 (enforcing) 或宽容 (permissive) 模式,不能够直接关闭 SELinux 的!同时,由 SELinux 关闭 (disable) 的状态到开启的状态也需要重新开机啦!

时间: 2024-08-06 20:08:22

Linux下开启关闭SeLinux的相关文章

Linux下开启关闭防火墙

一.Linux下开启/关闭防火墙命令 1) 永久性生效,重启后不会复原 开启: chkconfig iptables on 关闭: chkconfig iptables off 2) 即时生效,重启后复原 开启: /etc/init.d/iptables start 关闭: /etc/init.d/iptables stop 需要说明的是对于Linux下的其它服务都可以用以上命令执行开启和关闭操作. 在当开启了防火墙时,做如下设置,开启相关端口, 修改/etc/sysconfig/iptable

Linux下开启/关闭防火墙命令

一.Linux下开启/关闭防火墙命令 1) 永久性生效,重启后不会复原 开启: chkconfig iptables on 关闭: chkconfig iptables off 2) 即时生效,重启后复原 开启: service iptables start 关闭: service iptables stop 需要说明的是对于Linux下的其它服务都可以用以上命令执行开启和关闭操作. 在当开启了防火墙时,做如下设置,开启相关端口, 修改/etc/sysconfig/iptables 文件,添加以

Linux 下开启/关闭防火墙命令

一.Linux下开启/关闭防火墙命令 1) 永久性生效,重启后不会复原 开启: chkconfig iptables on 关闭: chkconfig iptables off 2) 即时生效,重启后复原 开启: service iptables start 关闭: service iptables stop 在当开启了防火墙时,做如下设置,开启相关端口,修改/etc/sysconfig/iptables 文件,添加以下内容:vi iptables -A RH-Firewall-1-INPUT

局域网内Linux下开启ftp服务的“曲折路”和命令复习

今天主要学习了Linux下网络配置以及vsftp(FTP)和samba的服务配置,学习起来,难度也就一般,并没有特别难,可是在可以做实验的时候,却并没有自己想像的那么顺利,可见,很多事情看起来不难,做起来却又是另外一回事.特作此篇以作纪念. 一:vsftpd 的配置. 1,首先,最好已经进行yum源的配置(如果没有配置,可以搜索我的日记,做好配置),方便于我们安装vsftpd. 只需一句命令即可: [[email protected] ~]# yum -y install vsftpd 喝杯茶,

Linux下开启MySQL的远程连接

Linux下开启MySQL的远程连接 基于安全考虑root账户一般只能本地访问,但是在开发过程中可能需要打开root的远程访问权限.下面是基本的步骤: 1.登录到mysql中,为root进行远程访问的授权,执行下面的命令: mysql> GRANT ALL PRIVILEGES ON *.* TO [email protected]"%" IDENTIFIED BY "root"; mysql> flush privileges; 第一句中"%

linux下开启ftp的21号端口

1.先运行vsftpd服务: #service vsftpd start 2.通过iptables开放21号端口 (1) 先查看iptables设置: #iptables -nL Chain INPUT (policy ACCEPT) target     prot opt source               destination ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTA

【linux系统优化】关闭Selinux

Selinux:SELinux(Security-EnhancedLinux) 是美国国家安全局(NSA)对于强制访问控制的实现,是 Linux历史上最杰出的新安全子系统. 虽然是一个安全功能,可是由于功能太多了,什么都要管,所以用起来反而更麻烦,因而可以把它关闭,进而使用其它的安全方式替代. [1]查看Selinux运行的3种模式 [[email protected] ~]#cat /etc/selinux/config     #此为Selinux的配置文件目录 # This filecon

LINUX服务开启关闭建议

1.操作系统centos5.5 服务名称 功能 默认 建议 备注 NetworkManager 用于自动连接网络 关闭 关闭 对服务器没用 acpid 电源的开关等检测管理 开启 关闭 对服务器没用 anacron 一种计划任务管理 开启 开启 apmd 高级电源管理 开启 开启 atd 在指定时间执行命令 开启 关闭 如果用crond,则可关闭它 auditd 开启 自定 如果用selinux,需要开启它 autofs 文件系统自动加载.卸载 开启 自定 只在需要时开启它,可以停止 avahi

Linux下开启nfs服务

1.什么是NFS(Network FileSystem) NFS 就是 Network FileSystem 的缩写,最早之前是由 Sun 所发展出来的.他最大的功能就是可以透过网络,让不同的机器.不 同的操作系统.可以彼此分享个别的档案 ( share file ),所以,也可以简单的将他看做是一个 file server 呢!这个  NFS Server 可以让你的 PC 来将网络远程的 NFS 主机分享的目录,挂载到本地端的机器当中,所以,在本地端的机器看起来,那个远程主 机的目录就好象是