笔记 :SElinux基础知识
来源:互联网 发布:老子的道是指什么 知乎 编辑:程序博客网 时间:2024/06/06 03:22
SElinux体系简介 (详见百科)
背景:
RHEL6.2
selinux基于默认的 targeted 策略
只关注安全上下文中的元素中的类型
selinux模式
1.Enforcing //强制
2.Permissive //警告 (但还是让你通过)
3.Disabled //关闭
#cat /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
在此文件中可更改模式和策略,但只有重启才能生效并具有永久性。
在系统运行时: 以下命令只是临时生效。重启后会还原到上面文件中的模式及策略。
[root@adp225 ~]# getenforce //查看现在模式
Enforcing
[root@adp225 ~]# setenforce 0 //更改为警告模式
[root@adp225 ~]# getenforce
Permissive
[root@adp225 ~]# setenforce 1 //更改为强制模式
[root@adp225 ~]# getenforce
Enforcing
注:在开机时在内核传递参数 selinux=0 或 selinux=1 也可以改变这次启动后的模式 。。
selinux Security Context
元素:
用户:角色:类型:敏感度:类别
user_u:object_r:tmp_t:s0:c0
并非所有系统都将显示:s0:c0
默认targeted策略主要使用类型元素
[root@adp225 ~]# ls -Z install.log
-rw-r--r--. root root system_u:object_r:admin_home_t:s0 install.log
[root@adp225 ~]# ls -Zd Music/
drwxr-xr-x. root root unconfined_u:object_r:admin_home_t:s0 Music/
[root@adp225 ~]# ps -Z aux |grep httpd
unconfined_u:system_r:httpd_t:s0 root 2315 0.0 0.7 186220 3924 ? Ss 17:20 0:00 /usr/sbin/httpd
unconfined_u:system_r:httpd_t:s0 apache 2318 0.0 0.4 186220 2464 ? S 17:20 0:00 /usr/sbin/httpdunconfined_u:system_r:httpd_t:s0 apache 2319 0.0 0.4 186220 2464 ? S 17:20 0:00 /usr/sbin/httpd
unconfined_u:system_r:httpd_t:s0 apache 2320 0.0 0.4 186220 2464 ? S 17:20 0:00 /usr/sbin/httpd
unconfined_u:system_r:httpd_t:s0 apache 2321 0.0 0.4 186220 2464 ? S 17:20 0:00 /usr/sbin/httpd
unconfined_u:system_r:httpd_t:s0 apache 2322 0.0 0.4 186220 2464 ? S 17:20 0:00 /usr/sbin/httpd
unconfined_u:system_r:httpd_t:s0 apache 2323 0.0 0.4 186220 2464 ? S 17:20 0:00 /usr/sbin/httpd
unconfined_u:system_r:httpd_t:s0 apache 2324 0.0 0.4 186220 2464 ? S 17:20 0:00 /usr/sbin/httpd
unconfined_u:system_r:httpd_t:s0 apache 2325 0.0 0.4 186220 2464 ? S 17:20 0:00 /usr/sbin/httpd
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 root 2333 0.0 0.1 103304 856 pts/0 S+ 17:21 0:00 grep httpd
在selinux体系中 unconfined_u:system_r:httpd_t:s0 称之为context值
例如httpd服务中用户访问网页 ,首先用户连接到server中httpd进程再由进程去访问需要的文件
chient---------server process-----------file
process的contest值必须与file的contest值对应 ,不对应则不能访问该文件。
[root@Aserver ~]# system-config-selinux//以图形方式显示所有的对应关系
[root@Aserver ~]# semanage fcontext -l |less//查看所有的对应关系
[root@Aserver ~]# chcon -R -t public_content_t /mydata/html //递归更改/mydata/html的类型为public_content_t 。此更改因某种原因重导context值时还是会变为数据库中的值
[root@Aserver ~]# semanage fcontext -a -t public_content_t '/mydata/html(/.*)' //把刚更改写入数据库
一些服务相对应的contest值得帮助
[root@Aserver ~]# man httpd_selinux
[root@Aserver ~]# man ftp_selinux
[root@Aserver ~]# man mamba_selinux
managing booleans
布尔值 :决定是否在运行时应用某些策略。off OR on
[root@Aserver ~]# getsebool -a //查看所有策略
allow_httpd_anon_write --> off
allow_httpd_mod_auth_ntlm_winbind --> off
allow_httpd_mod_auth_pam --> off
allow_httpd_sys_script_anon_write --> off
httpd_builtin_scripting --> on
httpd_can_check_spam --> off
httpd_can_network_connect --> off
httpd_can_network_connect_cobbler --> off
httpd_can_network_connect_db --> off
httpd_can_network_memcache --> off
httpd_can_network_relay --> off
httpd_can_sendmail --> off
httpd_dbus_avahi --> on
httpd_enable_cgi --> on
httpd_enable_ftp_server --> off
httpd_enable_homedirs --> off
httpd_execmem --> off
httpd_read_user_content --> off
httpd_setrlimit --> off
httpd_ssi_exec --> off
httpd_tmp_exec --> off
httpd_tty_comm --> on
httpd_unified --> on
httpd_use_cifs --> off
httpd_use_gpg --> off
httpd_use_nfs --> off
[root@Aserver ~]# setsebool httpd_enable_ftp_server on//开启
[root@Aserver ~]# setsebool httpd_enable_ftp_server off//关闭
以上更改只是在内存中更改 ,如需永久更改加 -P
[root@Aserver ~]# setsebool -P httpd_enable_ftp_server on//永久开启
故障排除
[root@remote ~]# cat /var/log/messages
[root@remote ~]# man -k selinux
包:setroubleshootd 提供selinux问题的解决方案
- 笔记 :SElinux基础知识
- selinux 基础知识
- selinux 基础知识
- selinux笔记
- selinux笔记
- SELinux/SEAndroid -- 基础知识介绍
- selinux学习笔记
- selinux学习笔记
- SELinux 学习笔记
- SElinux 学习笔记一
- SELinux 学习笔记
- linux笔记-selinux
- Linux学习记录(15)SELinux基础知识
- 1.【SELinux学习笔记】背景
- 2.【SELinux学习笔记】概念
- 3.【SELinux学习笔记】架构
- 7.【SELinux学习笔记】约束
- SElinux 学习笔记--例子实现
- 简单宏技巧
- 验证码
- 日语式样书常见语法问题
- 设计模式之创建型模式
- 黑马程序员_委托的使用
- 笔记 :SElinux基础知识
- Java继承和组合的区别
- 找出树中两个节点的最低公共祖先
- html语言
- heritrix学习
- 13.04.07 Turn the corner (三分)
- 解包system.img, cache.img,修改并重新打包
- Android动画效果translate、scale、alpha、rotate
- 海南三亚 十日十夜(一)