安全上下文是一个简单的、一致的访问控制属性,在SELinux中,类型标识符是安全上下文的主要组成部分,由于历史原因,一个进程的类型通常被称为一个域(domain),”域”和”域类型”意思都一样,即都是安全上下文中的“TYPE”。
SELinux对系统中的许多命令做了修改,通过添加一个-Z选项显示客体和主体的安全上下文。
1) 系统根据PAM子系统中的pam_selinux.so模块设定登录者运行程序的安全上下文;
2) 文件的Security Contex规则如下:
• rpm包安装的:会根据rpm包内记录来生成安全上下文;
• 手动创建的文件:会根据policy中规定的来设置安全上下文;
• cp:会重新生成安全上下文;
• mv:安全上下文则不变。
setenforce 1 强制(看不到)
setenforce 0 警告(可以看)
selinux的模式转换需要重启,因为selinux是内核级的插件。
[root@localhost ~]# vim /etc/sysconfig/selinux ##要把disabled改为enforcing
SELINUX=enforcing
[root@localhost ~]# getenforce #查看(未重启不生效)
Disabled
[root@localhost ~]# reboot ##重启
[root@localhost ~]# getenforce ##重启后生效
Enforcing
做以下实验需要重置虚拟机server,设置ip,配置yum源,安装服务
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# vim rhel_dvd.repo ##配置yum源文件
[root@localhost yum.repos.d]# yum clean all
Loaded plugins: langpacks
Cleaning repos: rhel_dvd source7.0
Cleaning up everything
[root@localhost yum.repos.d]# yum install vsftpd -y ##安装服务
[root@localhost yum.repos.d]# yum install lftp -y
[root@localhost ~]# systemctl start vsftpd
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
[root@localhost ~]# systemctl enable vsftpd
配置yum源:
一·临时更改上下文
[root@localhost ~]# touch /mnt/westos2
[root@localhost ~]# mv /mnt/westos2 /var/ftp/ ##移动是重命名的过程,权限不会改变,复制是新建的过程
[root@localhost ~]# lftp 172.25.254.219
lftp 172.25.254.219:~> ls ##看不到移动的文件
drwxr-xr-x 2 0 0 6 Mar 07 2014 pub
lftp 172.25.254.219:/> exit
[root@localhost ~]# cd /var/ftp/
[root@localhost ftp]# ls
pub westos2
[root@localhost ftp]# ls -Z ##查看安全上下文类型
drwxr-xr-x. root root system_u:object_r:public_content_t:s0 pub
-rw-r--r--. root root unconfined_u:object_r:mnt_t:s0 westos2
[root@localhost ftp]# chcon -t public_content_t westos2 ##更改上全上下文
[root@localhost ftp]# ls -Z ##查看更改成功
drwxr-xr-x. root root system_u:object_r: