SELINUX从理解到动手配置

ZDNet软件频道 时间:2009-11-05 作者: | 中国IT实验室 我要评论()
本文关键词:系统安全 SELINUX Linux
 SELinux 可以为你的系统提供较棒的安全防护。 使用者能被分配预先定义好的角色,以便他们不能存取文件或者访问他们不拥有的程序。

  SELINUX 可以为你的系统提供较棒的安全防护。 使用者能被分配预先定义好的角色,以便他们不能存取文件或者访问他们不拥有的程序。

  SELINUX的启用与关闭

  编辑/etc/SELINUX/conf文件

  SELINUX=enforcing(强制:违反了策略,你就无法继续操作下去)

  Permissive(有效,但不强制:违反了策略的话它让你继续操作,但是把你的违反的内容记录下来)

  Disabled(禁用)

  禁用的另一种方式:在启动的时候,也可以通过传递参数SELINUX给内核来控制它

  编辑/etc/grup.conf

  title Red Hat Enterprise Linux Server (2.6.18-8.el5)

  root (hd0,0)

  kernel /vmlinuz-2.6.18-8.el5 ro root=LABEL=/ rhgb quiet SELINUX=0

  initrd /initrd-2.6.18-8.el5.img

  SELINUXTYPE=targeted

  此参数可选项:targeted和strice。分别是targeted只控制关键网络服务,strice控制所有的服务

  查询SELINUX的状态

  [root@Linuxas ~]# /usr/sbin/getenforce

  Enforcing

  [root@Linuxas ~]# sestatus -bv

  SELINUX status: enabled

  SELINUXfs mount: /SELINUX

  Current mode: enforcing

  Mode from config file: enforcing

  Policy version: 21

  Policy from config file: targeted

  查看SELINUX加载的内核模块

  [root@Linuxas SELINUX]# semodule -l

  amavis 1.1.0

  ccs 1.0.0

  clamav 1.1.0

  dcc 1.1.0

  evolution 1.1.0

  iscsid 1.0.0

  mozilla 1.1.0

  mplayer 1.1.0

  nagios 1.1.0

  oddjob 1.0.1

  pcscd 1.0.0

  pyzor 1.1.0

  razor 1.1.0

  ricci 1.0.0

  smartmon 1.1.0

  查看SELINUX错误日志

  [root@Linuxas SELINUX]# sealert -a /var/log/audit/audit.log

  SELINUX的图形化管理工具

  [root@Linuxas SELINUX]# system-config-SELINUX

  SELINUX的基本操作

  查看文件:ls –Z(--context)

  [root@Linuxas ~]# ls -Z

  drwx------ root root root:object_r:user_home_t Desktop

  -rw------- root root system_u:object_r:user_home_t anaconda-ks.cfg

  -rw-r--r-- root root root:object_r:user_home_t install.log

  -rw-r--r-- root root root:object_r:user_home_t install.log.syslog

  [root@Linuxas ~]# ls --context

  drwx------ root root root:object_r:user_home_t Desktop

  -rw------- root root system_u:object_r:user_home_t anaconda-ks.cfg

  -rw-r--r-- root root root:object_r:user_home_t install.log

  -rw-r--r-- root root root:object_r:user_home_t install.log.syslog

  查看文件系统的扩展属性:getfattr

  [root@Linuxas ~]# getfattr -m. -d /etc/passwd

  getfattr: Removing leading "/" from absolute path names

  # file: etc/passwd

  security.SELINUX="system_u:object_r:etc_t:s000"

  查看的文件的 security.SELINUX 属性中储存了此文件的安全上下文, 所以上面例子中的上下文就是 system_ubject_r:etc_t 。

  所有运行了SE Linux的ext2/3文件系统上都有 security.SELINUX 这个属性。

  更改文件的扩展属性标签:chcon (不能在 /proc 文件系统上使用,就是说 /proc 文件系统不支持这种标记的改变。)

  [root@Linuxas test]# ls --context aa.txt

  -rw-r--r-- root root root:object_r:user_home_t aa.txt

  [root@Linuxas test]# chcon -t etc_t aa.txt

  [root@Linuxas test]# ls --context aa.txt

  -rw-r--r-- root root root:object_r:etc_t aa.txt

  恢复原来的文件标签: restorecon

  [root@Linuxas test]# restorecon aa.txt

  [root@Linuxas test]# ls -Z aa.txt

  -rw-r--r-- root root user_u:object_r:user_home_t aa.txt

  显示当前用户的SELINUX context

  [root@Linuxas ~]# id -Z

  root:system_r:unconfined_t:SystemLow-SystemHigh

  runcon 使用特定的context来执行指令

  [root@Linuxas ~]# runcon -t user_home_t cat /etc/passwd

  root:system_r:user_home_t:SystemLow-SystemHigh is not a valid context

  查看某种服务是否受到SELINUX的保护

  [root@Linuxas ~]# getsebool -a (RHEL4:inactive受保护,active不受保护;RHEL5:off受保护,on不受保护)


百度大联盟认证黄金会员Copyright© 1997- CNET Networks 版权所有。 ZDNet 是CNET Networks公司注册服务商标。
中华人民共和国电信与信息服务业务经营许可证编号:京ICP证010391号 京ICP备09041801号-159
京公网安备:1101082134