丹调生活 发表于 2018-11-22 13:49:43

SELINUX for APACHE VSFTP

  Selinux 基于APACHE 需要修改的内容
  1. 关闭iptables
12# service iptables statusiptables: Firewall is not running.  2. 启动Selinux
12# egrep '^SELINUX=' /etc/sysconfig/selinuxSELINUX=enforcing  3. 安装httpd服务
12# yum -y install httpd# yum -y install vim  4. 修改httpd配置文件
12345# cd /etc/httpd/conf/# cp httpd.conf httpd.conf.bak# vim httpd.conf#修改一行ServerName localhost:80  5. 启动httpd服务
1# service httpd start  6. 测试【1】

  7. 创建新的web目录
123# mkdir /www# cd /www/# echo 'This is test web'>index.html  8. 删除apache的欢迎页面,重新启动httpd服务
1234# rm -rf /etc/httpd/conf.d/welcome.conf# service httpd restartStopping httpd:                                          Starting httpd:                                            9. 测试【2】

  10. 使用新创建的web页面
1234# vim /etc/httpd/conf/httpd.conf#修改一下两行DocumentRoot "/www"  11. 重新加载配置文件
1# service httpd>  12. 测试【3】

  13. 为什么会没有权限呢?
  这个时候我们关闭selinux,在来继续访问
123# setenforce 0# getenforcePermissive  14. 测试【4】

  15. 看来真是selinux的问题,我们开启selinux ,然后通过修改selinux对文件的属性来访问服务
123# setenforce 1# getenforceEnforcing  16.查看文件对应的selinux属性值
12# ls -Z-rw-r--r--. root root unconfined_u:object_r:default_t:s0 index.html  17. 通过chcon修改对应的属性值
1234567891011# chcon --help |lessUsage: chcon ... CONTEXT FILE...or:chcon ... [-u USER] [-r ROLE] [-l RANGE] [-t TYPE] FILE...or:chcon ... --reference=RFILE FILE...Change the SELinux security context of each FILE to CONTEXT.# ls -Z /var/www/drwxr-xr-x. root root system_u:object_r:httpd_sys_script_exec_t:s0 cgi-bindrwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 errordrwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 htmldrwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 icons# chcon -t httpd_sys_content_t index.html  18. 测试【5】
  大家也看到了吧 在开启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后,这些功能形同样会失效。
  这时,就需要用到getsebool和setsebool了
  # 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 需要修改的内容
  # mkdir /erikxue
  # chmod 777 /erikxue
  # 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
  # ll -Z /ccc/
  drwxr-xr-x. nobody nobody unconfined_u:object_r:default_t:s0 /erikxue
  # chcon -u system_u /erikxue/
  #chcon -t samba_etc_t /erikxue/
  # ll -Zd /erikxue/
  drwxrwxrwx. root root system_u:object_r:samba_etc_t:s0 ccc
  同时需要开启布尔值
  # 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
  # setsebool -P
  Usage: setsebool [ -P ] boolean value | bool1=val1 bool2=val2...
  # setsebool-P samba_enable_home_dirs on
  # setsebool-P samba_export_all_rw 1

页: [1]
查看完整版本: SELINUX for APACHE VSFTP