內容選單標籤

2017年7月25日 星期二

Centos7 get SElinux to allow Apache and Samba on the same folder



-------------------------------先安裝httpd
# yum -y install httpd
# rpm -qa | grep httpd
httpd-2.4.6-45.el7.centos.4.x86_64
httpd-tools-2.4.6-45.el7.centos.4.x86_64


# systemctl start httpd.service
# systemctl enable httpd.service

# systemctl status httpd

# firewall-cmd --permanent --zone=public --add-service=http
# firewall-cmd --reload
# firewall-cmd --list-all

http://163.16.63.191/




-------------------------------虛擬目錄

# adduser kkweb01
# passwd kkweb01           //123456

# ls -l /home

drwx------. 2 kkweb01 kkweb01 62  7月 26 11:16 kkweb01

# chmod 755 /home/kkweb01
# ls -l /home
drwxr-xr-x. 2 kkweb01 kkweb01 80  7月 26 11:23 kkweb01


# vi /home/kkweb01/index.html

This is Visual Dir...


# vi /etc/httpd/conf/httpd.conf
...
Alias /web01 "/home/kkweb01"


<Directory "/home/kkweb01">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted

</Directory>


# systemctl restart httpd



# ls -dZ /home/kkweb01
drwxr-xr-x. kkweb01 kkweb01 unconfined_u:object_r:user_home_dir_t:s0 /home/kkweb01


# chcon -R -t public_content_rw_t /home/kkweb01


# ls -dZ /home/kkweb01

drwxr-xr-x. kkweb01 kkweb01 unconfined_u:object_r:public_content_rw_t:s0 /home/kkweb01


# setsebool -P allow_httpd_anon_write 1



----------------------------無效
# ls -Z /home
drwx------. kkweb01 kkweb01 unconfined_u:object_r:user_home_dir_t:s0 kkweb01



# chcon -R -t httpd_sys_content_t /home/kkweb01
# ls -Z /home
drwx------. kkweb01 kkweb01 unconfined_u:object_r:httpd_sys_content_t:s0 kkweb01
----------------------------


http://163.16.63.191/web01/
This is Visual Dir...




-------------------------------samba

# yum -y install samba

# rpm -qa | grep samba

samba-common-4.4.4-14.el7_3.noarch

samba-common-libs-4.4.4-14.el7_3.x86_64
samba-4.4.4-14.el7_3.x86_64
samba-client-libs-4.4.4-14.el7_3.x86_64
samba-common-tools-4.4.4-14.el7_3.x86_64
samba-libs-4.4.4-14.el7_3.x86_64


# ls -l /home
drwxr-xr-x. 2 kkweb01 kkweb01 80  7月 26 11:23 kkweb01

# chown -R nobody:nobody /home/kkweb01

# ls -l /home
drwxr-xr-x. 2 nobody nobody 80  7月 26 11:23 kkweb01


# vi /etc/samba/smb.conf
...


[global]

workgroup = WORKGROUP

server string = Samba Server %v
#netbios name = centos
security = user
map to guest = bad user
dns proxy = no

#===== Share Definitions ====
[Samba分享]
path = /home/kkweb01
browsable =yes
writable = yes
guest ok = yes
read only = no

# systemctl start smb.service


# firewall-cmd --permanent --zone=public --add-service=samba
# firewall-cmd --reload
# firewall-cmd --list-all



# setsebool -P allow_smbd_anon_write 1




----------------------------------------------------無效
# ln -s /home/kkweb01 /samba_share



# ls -l /

...

lrwxrwxrwx.   1 root root   13  7月 26 12:01 samba_share -> /home/kkweb01
...

# ls -Z /
...
lrwxrwxrwx. root root unconfined_u:object_r:root_t:s0  samba_share -> /home/kkweb01
...

# chcon -R -t samba_share_t /samba_share

# ls -Z /
...
lrwxrwxrwx. root root unconfined_u:object_r:samba_share_t:s0 samba_share -> /home/kkweb01
...
----------------------------------------------------



\\163.16.63.191\Samba分享