分析Selinux系统的配置及错误问题

本文发布时间: 2019-Mar-22
SELinux(Security-EnhancedLinux)是美国国家安全局(NAS)对于强制访问控制的实现,字面上的意思就是安全强化的linux之意。1.开启selinux后要重新启动系统才能生效2.也可以在修改[root@localhost~]#vim/etc/sysconfig/selinux6SELINUX=enforcing#设置为强制[root@localhost~]#vim/etc/sysconfig/i18nLANG="zh_CN.UTF-8"#中文界面没有图像界面解决2.安装apache测试selinux及排错[root@localhost~]#mount/dev/cdrom/mnt/cdrom/[root@localhostServer]#rpm-ivhhttpd-2.2.3-31.el5.i386.rpm设置默认主目录为/abc[root@localhost~]#mkdir/abc[root@localhost~]#vimindex.html[root@localhost~]#cd/etc/httpd/conf/[root@localhostconf]#vimhttpd.conf281DocumentRoot"/abc"开启selinux以后,再次启动httpd的时候发现已经不能启动了。而且selinux也会出现如下界面点击一下就会出现如下界面:如果没有安装图形界面可以通过查看日志:[root@localhost~]#tail-f/var/log/messages最后一行提示runsealert-l6d4b54ef-9617-48f0-9613-b7cc1e18f21b咱们试着运行一下:效果是一样的先把selinux的参数修改一下试试[root@localhost ~]# setenforce 0 /1 #0代表警告 但是可以运行,1代表强制[root@localhost ~]# getenforce #得到selinux的状态。Enforcing这样就不用重启系统,比较方便。把参数值改为0的时候是可起来的。1就不能起来 只要把目标和源的上下文修改为一致就可以了命令如下:[root@localhost ~]# chcon -R -t httpd_sys_content_t /abc设置完就可以正常启动和访问了。下面修改一下监听端口,发现又启动不了了[root@localhost ~]# cd /etc/httpd/conf[root@localhost conf]# vim httpd.conf134 Listen 800查看selinux支持的http端口[root@localhost ~]# semanage port -l |grep httphttp_cache_port_t tcp 3128, 8080, 8118, 11211, 10001-10010http_cache_port_t udp 3130, 11211http_port_t tcp 80, 443, 488, 8008, 8009, 8443pegasus_http_port_t tcp 5988pegasus_https_port_t tcp 59修改方法,把800加入到selinux支持http的端口[root@localhost ~]# semanage port -a -t http_port_t -p tcp 800重启一下,就可以基于端口访问例如:http://192.168.10.100:800/二.基于ftp的selinux配置[root@localhost ~]# yum install vsftpd -y添加用户如下[root@localhost Server]# useradd u1[root@localhost Server]# passwd u1[root@localhost ~]# cd /home/u1[root@localhost u1]# vim u1.txt #创建文件用于测试U1登录[root@localhost Server]# ftp 127.0.0.1ftp> dir227 Entering Passive Mode (127,0,0,1,49,10)150 Here comes the directory listing.226 Directory send OK.ftp> pwd257 "/home/u1"并没有发现u1.txt这个文件查看日志:Dec 22 21:52:18 localhost setroubleshoot: SELinux is preventing the ftp daemon from reading users home directories (/home/u1/u1.txt). For complete SELinux messages. run sealert -l f4d80bc3-3352-46c7-8aed-882c00493214 #selinux拒绝访问自己的家目录文件图形化解决[root@localhost ~]# system-config-selinux可以设置如下:把标准的选项勾选上就ok了也可以通过命令设置[root@localhost ~]# getsebool -aftp_home_dir --> offftpd_connect_db --> offftpd_disable_trans --> offftpd_is_daemon --> on将有关选项设置为ON[root@localhost ~]# setsebool -P ftp_home_dir=ON设置完以后就可以进行访问了查看如下:[root@localhost ~]# getsebool -a |grep ftpallow_ftpd_anon_write --> offallow_ftpd_full_access --> offallow_ftpd_use_cifs --> offallow_ftpd_use_nfs --> offallow_tftp_anon_write --> offftp_home_dir --> onSamba服务器selinux的配置部分安装[root@localhost Server]# rpm -ivh perl-Convert-ASN1-0.20-1.1.noarch.rpm[root@localhost Server]# rpm -ivh samba-3.0.33-3.14.el5.i386.rpm[root@localhost Server]# mkdir /aa[root@localhost Server]# cd /aa[root@localhost aa]# touch aa.txt[root@localhost aa]# vim /etc/samba/smb.conf282 [public]284 path = /aa285 public = yes添加smb用户,重启[root@localhost aa]# smbpasswd -a u1[root@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 权限不够命令修改如下[root@localhost ~]# chcon -R -t samba_share_t /aa[root@localhost~]#getsebool-a|grepsambasamba_domain_controller-->offsamba_enable_home_dirs-->offsamba_export_all_ro-->offsamba_export_all_rw-->offsamba_share_nfs-->offuse_samba_home_dirs-->offvirt_use_samba-->off[root@localhost~]#setsebool-Psamba_enable_home_dirs=ON测试可以发现可以访问操作命令:Vim/etc/sysconfig/selinuxSystem-config-selinuxSystem-config-securitylevel使用上述两个命令的话要重启。GetenforceSetenforce1|01表示强制0表示警告不需要重启改变策略库的方法:semanagesemanage{login|user|port|interface|fcontext|translation}-l[-n]semanagelogin-{a|d|m}[-sr]login_namesemanageuser-{a|d|m}[-LrRP]selinux_namesemanageport-{a|d|m}[-tr][-pprotocol]port|port_rangesemanageinterface-{a|d|m}[-tr]interface_specsemanagefcontext-{a|d|m}[-frst]file_specsemanagetranslation-{a|d|m}[-T]level


(以上内容不代表本站观点。)
---------------------------------
本网站以及域名有仲裁协议。
本網站以及域名有仲裁協議。

2024-Mar-04 02:11pm
栏目列表