[root@localhost(cyn) ~]$ getenforce #查看状态
Enforcing
[root@localhost(cyn) ~]$ setenforce 0 #设置状态
[root@localhost(cyn) ~]$ getenforce
Permissive
[root@localhost(cyn) /]$ sestatus #查看当前selinux的状态
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: permissive
Mode from config file: enforcing
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 31 enforcing: 强制,每个受限的进程都必然受限
permissive: 允许,每个受限的进程违规操作不会被禁止,但会被记录于审计日志
disabled: 禁用
要是想禁用selinux,可根据配置文件设置,如下
bash-4$ vim /boot/grub/grub.conf #系统启动加载内核karnel的时候编辑grun.conf文件
#不写selinux=0,系统则默认为开启,值为1
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/mapper/vg_centos6-lv_root
# initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS 6 (2.6.32-696.el6.x86_64)
root (hd0,0) kernel /vmlinuz-2.6.32-696.el6.x86_64 ro root=/dev/mapper/vg_centos6-lv_root rhgb quiet selinux=0
initrd /initramfs-2.6.32-696.el6.x86_64.img
[root@localhost(cyn) /]$ vim /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 #修改selinux开启关闭,enforcing|disabled
# 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 2. SELinux的安全标签
a. 安全上下文恢复
[root@localhost(cyn) ~]$ ls -Z
-rw-r--r--. root root unconfined_u:object_r:admin_home_t:s0 magedu.repo
[root@localhost(cyn) ~]$ cd /zuoye/
[root@localhost(cyn) zuoye]$ ls -Z magedu.repo
-rw-r--r--. root root unconfined_u:object_r:admin_home_t:s0 magedu.repo
[root@localhost(cyn) zuoye]$ restorecon magedu.repo
[root@localhost(cyn) zuoye]$ ls -Z magedu.repo
-rw-r--r--. root root unconfined_u:object_r:default_t:s0 magedu.repo 用mv命令复制一个文件的时候会保留selinux,然后可以利用restorcon恢复文件默认的安全上下文,支持-R
b . 安全上下文的操作
sealert -l UUID 查看安全事件日志说明
sealert -a /var/log/audit/audit.log 扫描并分析日志
八、实例
1.配置vsftpd,实现匿名上传
[root@centos6(cyn) ~]$ yum -y install vsftpd #安装服务
[root@centos6(cyn) ~]$ vim /etc/vsftpd/vsftpd.conf #修改配置文件
# Example config file /etc/vsftpd/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anon_upload_enable=YES #可以上传
anon_mkdir_write_enable=YES #开启写操作
[root@centos6(cyn) ~]$ service vsftpd restart
Shutting down vsftpd: [ OK ]
Starting vsftpd for vsftpd: [ OK ]
[root@centos6(cyn) ~]$ setfacl -m u:ftp:rwx /var/ftppub/
[root@centos6(cyn) ~]$ chcon -t public_content_rw_t /var/ftp/pub #修改上下文的type
[root@centos6(cyn) ~]$ setsebool -P allow_ftpd_anon_write on #设置布尔值
[root@centos6(cyn) ~]$ lftp ip#进入客户端开始匿名上传 2.配置httpd开启用户家目录的访问
[root@centos6(cyn) ~]$ yum -y install httpd
[root@centos6(cyn) ~]$ vim /etc/httpd/conf/httpd.conf
#
# This is the main Apache server configuration file. It contains the
# configuration directives that give the server its instructions.
# See for detailed information.
# In particular, see
#
# for a discussion of each configuration directive.
#
#
# Do NOT simply read the instructions in here without understanding
# what they do. They're here only as hints or reminders. If you are unsure
# consult the online docs. You have been warned.
# UserDir disabled #这一行注释
UserDir public_html
[root@centos6(cyn) ~]$ service httpd restart #重新启动服务,配置生效
[root@centos6(cyn) ~]$ useradd testhttpd #创建用户
[root@centos6(cyn) ~]$ mkdir /home/testhttpd/public_html
[root@centos6(cyn) ~]$ echo "testhttpd home" > /home/testhttpd/public_html/index.html
[root@centos6(cyn) ~]$ setfacl -m u:apache:x /home/testhttpd / #设置期望值
[root@centos6(cyn) ~]$ setsebool -P httpd_enable_homedirs=1 #selinux的布尔值永久生效
浏览器输入IP即可生效 其他的可以查看帮助文档