手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

SELinux管理与应用

[日期:2012-12-05] 来源:Linux社区  作者:Linux [字体:大 中 小]

3.策略的位置
/etc/selinux/<策略名>/policy/

1.2 SElinux命令介绍
1.2.1 查询SElinux状态命令
1.查询selinux状态

[root@RedHat ~]# sestatus
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: enforcing
Mode from config file: enforcing
Policy version: 21
Policy from config file: targeted

2.查询selinux激活状态
[root@redhat ~]# selinuxenabled
[root@redhat ~]# echo $?
0
如果为-256为非激活状态。
1.2.2 切换SElinux类型
1.切换成警告模式

[root@redhat ~]# setenforce 0或setenforce permissive
[root@redhat ~]# sestatus
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: permissive
Mode from config file: enforcing
Policy version: 21
Policy from config file: targeted
或
[root@redhat ~]# getenforce
Permissive

2.切换成强制模式
[root@redhat ~]# setenforce 1
[root@redhat ~]# getenforce
Enforcing
注:使用setenforce切换enforcing与permissive模式不需要重启计算机。
1.2.3 检查安全上下文
1.检查帐号的安全上下文

[root@redhat ~]# id -Z
root:system_r:unconfined_t:SystemLow-SystemHigh

2.检查进程的安全上下文
[root@redhat home]# ps -Z
LABEL PID TTY TIME CMD
root:system_r:unconfined_t:SystemLow-SystemHigh 2383 pts/0 00:00:00 bash
root:system_r:unconfined_t:SystemLow-SystemHigh 2536 pts/0 00:00:00 ps

3.检查文件与目录的安全上下文
[root@redhat home]# ls -Z
drwx------ tom tom system_u:object_r:user_home_dir_t tom
1.2.4 修改文件/目录安全上下文与策略
1.chcon命令

chcon -u [user] 对象
-r [role]
-t [type]
-R 递归
示例:
chcon -R -t samba_share_t /tmp/abc
注:安全上下文的简单理解说明,受到selinux保护的进程只能访问标识为自己只够访问的安全上下文的文件与目录。
例如:上面解释为使用smb进程能够访问/tmp/abc目录而设定的安全上下文。

2.getsebool命令
获取本机selinux策略值,也称为bool值。
getsebool -a 命令同sestatus -b
[root@redhat files]# getsebool -a
NetworkManager_disable_trans --> off
allow_cvs_read_shadow --> off
allow_daemons_dump_core --> on
allow_daemons_use_tty --> off
allow_execheap --> off
allow_execmem --> on
allow_execmod --> off
allow_execstack --> on
allow_ftpd_anon_write --> off /*是否允许ftp匿名访问*/
allow_ftpd_full_access --> off
...
httpd_disable_trans --> off /*只要有disable_trans关闭保护*/

说明:selinux的设置一般通过两个部分完成的,一个是安全上下文,另一个是策略,策略值是对安全上下文的补充。

linux
相关资讯       SELinux 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款