SELinux(Security-EnhancedLinux)是美国国家安全局(NAS)对于强制访问控制的实现,字面上的意思就是安全强化的linux之意。
1.开启selinux 后要重新启动系统才能生效
2.也可以在修改 [iyunv@localhost ~]# vim /etc/sysconfig/selinux 6 SELINUX=enforcing #设置为强制 [iyunv@localhost ~]# vim /etc/sysconfig/i18n LANG="zh_CN.UTF-8" #中文界面
没有图像界面解决 2.安装apache 测试selinux 及排错 [iyunv@localhost ~]# mount /dev/cdrom /mnt/cdrom/ [iyunv@localhost Server]# rpm -ivh httpd-2.2.3-31.el5.i386.rpm 设置默认主目录为/abc [iyunv@localhost ~]# mkdir /abc [iyunv@localhost ~]# vim index.html [iyunv@localhost ~]# cd /etc/httpd/conf/ [iyunv@localhost conf]# vim httpd.conf 281 DocumentRoot "/abc" 开启selinux以后,再次启动httpd的时候发现已经不能启动了。 而且selinux也会出现如下界面
点击一下就会出现如下界面:
如果没有安装图形界面可以通过查看日志: [iyunv@localhost ~]# tail -f /var/log/messages 最后一行提示 run sealert -l 6d4b54ef-9617-48f0-9613-b7cc1e18f21b 咱们试着运行一下:效果是一样的
先把selinux的参数修改一下试试 [iyunv@localhost ~]# setenforce 0 /1 #0代表警告 但是可以运行,1代表强制 [iyunv@localhost ~]# getenforce #得到selinux的状态。 Enforcing 这样就不用重启系统,比较方便。把参数值改为0的时候是可起来的。1就不能起来 只要把目标和源的上下文修改为一致就可以了 命令如下: [iyunv@localhost ~]# chcon -R -t httpd_sys_content_t /abc 设置完就可以正常启动和访问了。 下面修改一下监听端口,发现又启动不了了 [iyunv@localhost ~]# cd /etc/httpd/conf [iyunv@localhost conf]# vim httpd.conf 134 Listen 800 查看selinux支持的http端口 [iyunv@localhost ~]# semanage port -l |grep http http_cache_port_t tcp 3128, 8080, 8118, 11211, 10001-10010 http_cache_port_t udp 3130, 11211 http_port_t tcp 80, 443, 488, 8008, 8009, 8443 pegasus_http_port_t tcp 5988 pegasus_https_port_t tcp 59 修改方法,把800加入到selinux支持http的端口 [iyunv@localhost ~]# semanage port -a -t http_port_t -p tcp 800 重启一下,就可以基于端口访问 例如: 也可以通过命令设置 [iyunv@localhost ~]# getsebool -a ftp_home_dir --> off ftpd_connect_db --> off ftpd_disable_trans --> off ftpd_is_daemon --> on 将有关选项设置为ON [iyunv@localhost ~]# setsebool -P ftp_home_dir=ON 设置完以后就可以进行访问了 查看如下: [iyunv@localhost ~]# getsebool -a |grep ftp allow_ftpd_anon_write --> off allow_ftpd_full_access --> off allow_ftpd_use_cifs --> off allow_ftpd_use_nfs --> off allow_tftp_anon_write --> off ftp_home_dir --> on Samba服务器selinux的配置部分 安装 [iyunv@localhost Server]# rpm -ivh perl-Convert-ASN1-0.20-1.1.noarch.rpm [iyunv@localhost Server]# rpm -ivh samba-3.0.33-3.14.el5.i386.rpm [iyunv@localhost Server]# mkdir /aa [iyunv@localhost Server]# cd /aa [iyunv@localhost aa]# touch aa.txt [iyunv@localhost aa]# vim /etc/samba/smb.conf 282 [public] 284 path = /aa 285 public = yes 添加smb用户,重启 [iyunv@localhost aa]# smbpasswd -a u1 [iyunv@localhost aa]# service smb start 访问如下:
输入用户和密码点击 u1和public都无法访问
查看日志显示权限不够。 Dec 22 22:30:56 localhost smbd[4866]: '/home/u1' does not exist or permission denied when connecting to [u1] Error was 权限不够 命令修改如下 [iyunv@localhost ~]# chcon -R -t samba_share_t /aa
[iyunv@localhost ~]# getsebool -a |grep samba samba_domain_controller --> off samba_enable_home_dirs --> off samba_export_all_ro --> off samba_export_all_rw --> off samba_share_nfs --> off use_samba_home_dirs --> off virt_use_samba --> off [iyunv@localhost ~]# setsebool -P samba_enable_home_dirs=ON 测试可以发现可以访问 操作命令: Vim /etc/sysconfig/selinux System-config-selinux System-config-securitylevel 使用上述两个命令的话要重启。 Getenforce Setenforce 1 | 0 1表示强制 0 表示警告 不需要重启 改变策略库的方法: semanage semanage {login|user|port|interface|fcontext|translation} -l [-n] semanage login -{a|d|m} [-sr] login_name semanage user -{a|d|m} [-LrRP] selinux_name semanage port -{a|d|m} [-tr] [-p protocol] port | port_range semanage interface -{a|d|m} [-tr] interface_spec semanage fcontext -{a|d|m} [-frst] file_spec semanage translation -{a|d|m} [-T] level
|