Selinux 基于SAMBA 需要修改的内容
[root@server1 pub]# mkdir /ccc
[root@server1 pub]# chmod 777 /ccc
[root@server1 pub]# ls -Z /etc/samba/
-rw-r--r--. root root system_u:object_r:samba_etc_t:s0 lmhosts
-rw-r--r--. root root system_u:object_r:samba_etc_t:s0 smb.conf
-rw-r--r--. root root system_u:object_r:samba_etc_t:s0 smbusers
[root@server1 pub]# ll -Z /ccc/
drwxr-xr-x. nobody nobody unconfined_u:object_r:default_t:s0 /ccc
[root@server1 pub]# chcon -u system_u /ccc/
[root@server1 pub]# chcon -t samba_etc_t /ccc/
[root@server1 pub]# ll -Zd /ccc/
drwxrwxrwx. root root system_u:object_r:samba_etc_t:s0 ccc
同时需要开启布尔值
[root@server1 /]# getsebool -a | grep samba
samba_create_home_dirs --> off
samba_domain_controller --> off
samba_enable_home_dirs --> off
samba_export_all_ro --> off
samba_export_all_rw --> off
samba_run_unconfined --> off
samba_share_fusefs --> off
samba_share_nfs --> off
use_samba_home_dirs --> off
virt_use_samba --> off
[root@server1 /]# setsebool -P
Usage: setsebool [ -P ] boolean value | bool1=val1 bool2=val2...
[root@server1 /]# setsebool -P samba_enable_home_dirs on
[root@server1 /]# setsebool -P samba_export_all_rw 1
SElinux 基于 APACHE 的策略
1. 关闭iptables
# service iptables status
iptables: Firewall is running.
# service iptables stop
2. 启动Selinux
[root@allentuns ~]# cat /etc/sysconfig/selinux | grep “SELINUX=”
SELINUX=enforcing
3. 安装httpd服务
#yum -y install httpd
4. 修改httpd配置文件
# cd /etc/httpd/conf/
# cp httpd.conf httpd.conf.bak
# vim httpd.conf
5. 启动httpd服务
# service httpd start
#修改一行
ServerName localhost:80
6. 测试【1】
7. 创建新的web目录
#mkdir /www
#cd /www/
# echo '<h1>This is test web</h1>' > index.html
8. 删除apache的欢迎页面,重新启动httpd服务
#rm -rf /etc/httpd/conf.d/welcome.conf
#service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
9. 测试【2】
10. 使用新创建的web页面
# vim /etc/httpd/conf/httpd.conf
#修改一下两行
DocumentRoot "/www"
<Directory "/www">
11. 重新加载配置文件
# service httpd reload
12. 测试【3】
13. 为什么会没有权限呢?
这个时候我们关闭selinux,在来继续访问
#setenforce 0
#getenforce
Permissive
14. 测试【4】
看来真是selinux的问题,我们开启selinux ,然后通过修改selinux对文件的属性来访问服务
# setenforce 1
# getenforce
Enforcing
16.查看文件对应的selinux属性值
#ls -Z
-rw-r--r--. root root unconfined_u:object_r:default_t:s0 index.html
17. 通过chcon修改对应的属性值
# chcon --help |less
Usage: chcon [OPTION]... CONTEXT FILE...
or: chcon [OPTION]... [-u USER] [-r ROLE] [-l RANGE] [-t TYPE] FILE...
or: chcon [OPTION]... --reference=RFILE FILE...
Change the SELinux security context of each FILE to CONTEXT.
[root@allentuns www]# ls -Z /var/www/
drwxr-xr-x. root root system_u:object_r:httpd_sys_script_exec_t:s0 cgi-bin
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 error
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 html
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 icons
[root@allentuns www]# chcon -t httpd_sys_content_t index.html
18. 测试【5】
大家也看到了吧 在开启Selinux的情况下 修改修改文本的属性值,也可以保证服务的安全!!