SELINUX for APACHE VSFTP



   Selinux 基於APACHE 需要修改的內容

1. 關閉iptables

1
2
[root@allentuns ~]# service iptables status
iptables: Firewall is not running.

2. 啓動Selinux

1
2
[root@allentuns ~]# egrep '^SELINUX=' /etc/sysconfig/selinux
SELINUX=enforcing

3. 安裝httpd服務

1
2
# yum -y install httpd
# yum -y install vim

4. 修改httpd配置文件

1
2
3
4
5
[root@allentuns ~]# cd /etc/httpd/conf/
[root@allentuns conf]# cp httpd.conf httpd.conf.bak
[root@allentuns conf]# vim httpd.conf
#修改一行
ServerName localhost:80

5. 啓動httpd服務

1
# service httpd start

6. 測試【1】

wKioL1NKVJDyuMzFAAYFFbY_it4430.jpg

7. 創建新的web目錄

1
2
3
[root@allentuns ~]# mkdir /www
[root@allentuns ~]# cd /www/
[root@allentuns www]# echo '<h1>This is test web</h1>'>index.html

8. 刪除apache的歡迎頁面,重新啓動httpd服務

1
2
3
4
[root@allentuns www]# rm -rf /etc/httpd/conf.d/welcome.conf
[root@allentuns www]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

9. 測試【2】

wKiom1NKVkKzzUD0AAIecFlBt3k193.jpg


10. 使用新創建的web頁面

1
2
3
4
[root@allentuns www]# vim /etc/httpd/conf/httpd.conf
#修改一下兩行
DocumentRoot "/www"
<Directory "/www">

11. 重新加載配置文件

1
[root@allentuns www]# service httpd reload

12. 測試【3】

wKioL1NKV5mwdmfBAAJU7D5Z1tc286.jpg


13. 爲什麼會沒有權限呢?
這個時候我們關閉selinux,在來繼續訪問

1
2
3
[root@allentuns www]# setenforce 0
[root@allentuns www]# getenforce
Permissive

14. 測試【4】

wKiom1NKWLfxvSEhAAHIEh9FGss092.jpg


15. 看來真是selinux的問題,我們開啓selinux ,然後通過修改selinux對文件的屬性來訪問服務

1
2
3
[root@allentuns www]# setenforce 1
[root@allentuns www]# getenforce
Enforcing

16.查看文件對應的selinux屬性值

1
2
[root@allentuns www]# ls -Z
-rw-r--r--. root root unconfined_u:object_r:default_t:s0 index.html

17. 通過chcon修改對應的屬性值

1
2
3
4
5
6
7
8
9
10
11
[root@allentuns www]# 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】wKiom1NKWmGw8GrNAAHQEuwedtU510.jpg


大家也看到了吧 在開啓Selinux的情況下 修改修改文本的屬性值,也可以保證服務的安全!!



_______________________________________________________________________________________________

          Selinux 基於APACHE 需要修改的內容


一、如何讓暱名用戶能夠上傳文件到ftp服務器?


1,修改ftp目錄的訪問權限


# cd /var/ftp/


# setfacl -m u:ftp:rwx pub


2,修改配置文件/etc/vsftp/vsftp.conf


anonymous_enable=YES-----------暱名登錄ftp


anon_upload_enable=YES---------暱名上傳


anon_mkdir_write_enable=YES------暱名創建目錄


anon_other_write_enable=YES------暱名進行其他操作


3,登錄ftp上傳文件


# lftp localhost  -----------登錄ftp服務器


lftp localhost:/pub> cd pub ----------------------- 進入pub目錄


lftp localhost:/pub> lcd /etc-------------------------進入文件系統的/etc目錄,注意lcd命令,對於cd命令,這裏使用lcd,其他命令可以使用!命令,如!Ls,顯示的就是進入ftp前的當前目錄。


lftp localhost:/pub> put shadow


868 bytes transferred



然而,開啓了selinux後,這些功能形同樣會失效。


這時,就需要用到getseboolsetsebool


# getsebool -a | grep ftp--------------顯示所有與ftp有關的功能開關


allow_ftpd_anon_write --> off-----------開啓selinux後,默認暱名用戶無寫權限


allow_ftpd_full_access --> off-----------默認無訪問權限


allow_ftpd_use_cifs --> off


allow_ftpd_use_nfs --> off


ftp_home_dir --> off


ftpd_connect_db --> off


ftpd_use_passive_mode --> off


httpd_enable_ftp_server --> off


tftp_anon_write --> off


要想暱名用戶能夠上傳,這時就需要啓用這兩個功能了。


# setsebool -P allow_ftpd_anon_write=1


# setsebool -P allow_ftpd_anon_write=on


以上兩種任選一種。


-P選項,表示永久有效。


# setsebool -P allow_ftpd_full_access=1


這樣,暱名用戶就可以再次上傳了。


_________________________________________________________________________________________________________

Selinux 基於SAMBA 需要修改的內容


[root@server1 pub]# mkdir /erikxue

[root@server1 pub]# chmod 777 /erikxue

[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 /erikxue

[root@server1 pub]# chcon -u system_u /erikxue/

[root@server1 pub]#chcon -t samba_etc_t /erikxue/

[root@server1 pub]# ll -Zd /erikxue/

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



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章