selinux简介:
SELinux是美国国家安全局对于强制访问控制的实现,是 Linux历史上最杰出的新安全子系统。
SELINUX有「disabled」「permissive」,「enforcing」3种模式选择。
Disabled就是关闭。
permissive就是Selinux有效,但是即使你违反了策略的话它让你继续操作,但是把你的违反的内容记录下来。
Enforcing就是你违反了策略,你就无法继续操作下去。
selinux的模式转换需要重启,因为selinux是内核级的插件。
[root@localhost yum.repos.d]# vim /etc/sysconfig/selinux 将disabled改为enforcing
[root@localhost yum.repos.d]# getenforce 未重启不生效
Disabled
[root@localhost yum.repos.d]# reboot 重启
[kiosk@foundation21 Desktop]$ ssh root@172.25.254.221 连接虚拟机
[root@localhost ~]# getenforce 查看生效
Enforcing
进行虚拟机的配置:
[root@localhost ~]# vim /etc/sysconfig/selinux更改为Enforce即可
[root@localhost yum.repos.d]# getenforce
Enforcing
[root@localhost yum.repos.d]# vim yum.repo 配置yum源
[root@localhost yum.repos.d]# cat yum.repo
[source7.0]
name=source7.0
baseurl=http://172.25.254.84/source7.0
gpgcheck=0
[root@localhost ~]# yum install vsftpd lftp -y 安装服务
[root@localhost ~]# systemctl start vsftpd 开始服务
[root@localhost ~]# systemctl enable vsftpd 开机自启动
ln -s '/usr/lib/systemd/system/vsftpd.service' '/etc/systemd/system/multi-user.target.wants/vsftpd.service'
[root@localhost ~]# systemctl stop firewalld 关闭火墙
[root@localhost ~]# systemctl disable firewalld 开机自动关闭
配置IP和yum源,设置selinux为强制。
安装服务开机自启动并设置开机自动关闭防火墙。
设置selinux安全上下文有临时设定和永久设定之分
1,临时设定安全上下文:
[root@localhost ~]# mkdir /westos
[root@localhost ~]# touch /westos/westosfile 建立文件安全上下文不改变就无法查看
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf 编辑配置文件
添加家目录:anon_root=/westos
[root@localhost ~]# systemctl restart vsftpd 重启服务
[root@localhost ~]# lftp 172.25.254.221 查看家目录中没有我们建立的文件
lftp 172.25.254.221:~> ls
[root@localhost ~]# vim /etc/sysconfig/selinux 查看selinux状态
[root@localhost ~]# getenforce 为强制即可
Enforcing
[root@localhost ~]# ls -Z /westos/ 查看
-rw-r--r--. root root unconfined_u:object_r:default_t:s0 westosfile
[root@localhost ~]# chcon -t public_content_t /westos -R 更改安全上下文
[root@localhost ~]# ls -Z /westos/ 已经更改成功
-rw-r--r--. root root unconfined_u:object_r:public_content_t:s0 westosfile
[root@localhost ~]# lftp 172.25.254.221 查看可以显示我们建立的文件
lftp 172.25.254.221:~> ls
-rw-r--r-- 1 0 0 0 May 12 02:01 westosfile
临时配置安全上下文之后就可以看到家目录下的文件。
但是这种设定是临时的,重启selinux失效,这里的重启指的是selinux的重启,因为selinux是内核级别的,所以需要来回重启系统。
[root@localhost ~]# vim /etc/sysconfig/selinux 更改为disabled
[root@localhost ~]# getenforce 重启生效,已经变为disabled
Disabled
[roo