setsebool命令

配置VSFTPD时本地用户无法切换

用到命令

setsebool -P allow_ftpd_anon_write=1 allow_ftpd_full_access=1 ftp_home_dir=1 ftpd_disable_trans=1 ftpd_is_daemon=1

setsebool命令查询了相关的资料

是selinux的相关设置项

这是SELinux的设置命令.
其实 man 一下setsebool也知道了:
NAME
setsebool – set SELinux boolean value
在不熟悉SELnux前,把SELinux关掉也可以的。有时间研究下SELinux。

Redhat从FC3开始,就使用了SELinux来增强安全,但是使用起来有时候太繁琐,就想关闭它,但是如果安装服务器的时候开始没有图形界面,还真很难找到地方可以关闭。

正确方法如下:修改/etc/selinux/config文件中的SELINUX=”" 为 disabled ,然后重启。

2009年8。22更新

下面是一些 收集来的 设置命令
===ftp===
//If you want to share files anonymously
chcon -R -t public_content_t /var/ftp
//If you want to setup a directory where you can upload files
chcon -t public_content_rw_t /var/ftp/incoming
You must also turn on the boolean allow_ftpd_anon_write
setsebool -P allow_ftpd_anon_write=1
//If you are setting up this machine as a ftpd server and wish to allow users to access their home directorories
setsebool -P ftp_home_dir 1
//If you want to run ftpd as a daemon
setsebool -P ftpd_is_daemon 1
//You can disable SELinux protection for the ftpd daemon
setsebool -P ftpd_disable_trans 1

===httpd===
//If you want a particular domain to write to the public_content_rw_t domain
setsebool -P allow_httpd_anon_write=1
or
setsebool -P allow_httpd_sys__anon_write=1
//httpd can be setup to allow cgi s to be executed
setsebool -P httpd_enable_cgi 1
//If you want to allow access to users home directories
setsebool -P httpd_enable_homedirs 1
chcon -R -t httpd_sys_content_t ~user/public_html
//httpd is allowed access to the controling terminal
setsebool -P httpd_tty_comm 1
//such that one httpd service can not interfere with another
setsebool -P httpd_unified 0
//loadable modules run under the same context as httpd
setsebool -P httpd_builtin_ing 0
//httpd s are allowed to connect out to the network
setsebool -P httpd_can_network_connect 1
// You can disable suexec transition
setsebool -P httpd_suexec_disable_trans 1
//You can disable SELinux protection for the httpd daemon by executing
setsebool -P httpd_disable_trans 1
service httpd restart

===named===
//If you want to have named update the master zone files
setsebool -P named_write_master_zones 1
//You can disable SELinux protection for the named daemon by executing
setsebool -P named_disable_trans 1
service named restart

===nfs===
//If you want to setup this machine to share nfs partitions read only
setsebool -P nfs_export_all_ro 1
//If you want to share files read/write
setsebool -P nfs_export_all_rw 1
//If you want to use a remote NFS server for the home directories on this machine
setsebool -P use_nfs_home_dirs 1

===samba===
//If you want to share files other than home directorie
chcon -t samba_share_t /directory
//If you want to share files with multiple domains
setsebool -P allow_smbd_anon_write=1
//If you are setting up this machine as a Samba server and wish to share the home directories
setsebool -P samba_enable_home_dirs 1
//If you want to use a remote Samba server for the home directories on this machine
setsebool -P use_samba_home_dirs 1
//You can disable SELinux protection for the samba daemon by executing
setsebool -P smbd_disable_trans 1
service smb restart

===rsync===
//If you want to share files using the rsync daemon
chcon -t public_content_t /directories
//If you want to share files with multiple domains
setsebool -P allow_rsync_anon_write=1
//You can disable SELinux protection for the rsync daemon by executing
setsebool -P rsync_disable_trans 1

===kerberos===
//allow your system to work properly in a Kerberos environment
setsebool -P allow_kerberos 1
//If you are running Kerberos daemons kadmind or krb5kdc
setsebool -P krb5kdc_disable_trans 1
service krb5kdc restart
setsebool -P kadmind_disable_trans 1
service kadmind restart

===nis===
Allow your system to work properly in a NIS environment
setsebool -P allow_ypbind 1

1.1 SElinux概述 
SELinux(Security-Enhanced Linux) 是美国国家安全局(NAS)对于强制访问控 制的实现,在这种访问控制体系的限制下,进程只能访问那些在他的任务中所需要文件。大部分使用 SELinux 的人使用的都是SELinux就绪的发行版,例如 Fedora、Red Hat Enterprise Linux (RHEL)、Debian 或 Gentoo。它们都是在内核中启用 SELinux 的,并且提供一个可定制的安全策略,还提供很多用户层的库和工具,它们都可以使用 SELinux 的功能。 
1.1.1 SElinux特点 
1.MAC 
对访问的控制彻底化,对所有的文件、目录、端口的访问都是基于策略设定的,可由管理员时行设定。 
2.RBAC 
对于用户只赋予最小权限。用户被划分成了一些role(角色),即使是root用户,如果不具有sysadm_r角色的话,也不是执行相关的管理。哪里role可以执行哪些domain,也是可以修改的。 
3.安全上下文 
当启动selinux的时候,所有文件与对象都有安全上下文。进程的安全上下文是域,安全上下文由用户:角色:类型表示。 
(1)系统根据pam子系统中的pam_selinux.so模块设定登录者运行程序的安全上下文 
(2)rpm包安装会根据rpm包内记录来生成安全上下文, 
(3)如果是手工他建的,会根据policy中规定来设置安全上下文, 
(4)如果是cp,会重新生成安全上下文。 
(5)如果是mv,安全上下文不变。 
1.1.2 安全上下文格式 
安全上下文由user:role:type三部分组成,下面分别说明其作用: 
1.user identity:类似linux系统中的UID,提供身份识别,安全上下文中的一部分。 
三种常见的user: 
user_u-: 普通用户登录系统后预设; 
system_u-:开机过程中系统进程的预设; 
root-: root登录后预设; 
在targeted policy中users不是很重要; 
在strict policy中比较重要,的有预设的selinux users都以 "_u"结尾,root除外。 
2.role 
文件与目录的role,通常是object_r; 
程序的role,通常是system_r; 
用户的role,targeted policy为system_r; 
strict policy为sysadm_r,staff_r,user_r 
用户的role,类似于系统中的GID,不同的角色具备不同的权限;用户可以具备多个role;但是同一时间内只能使用一role; 
role是RBAC的基础; 
3.type 
type:用来将主体与客体划分为不同的组,组每个主体和系统中的客体定义了一个类型;为进程运行提供最低的权限环境。 
当一个类型与执行的进程关联时,该type也称为domain,也叫安全上下文。 
域或安全上下文是一个进程允许操作的列表,决字一个进程可以对哪种类型进行操作。 
1.1.3 SElinux配置文件 
vi /etc/selinux/config 
# 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 - SELinux is fully disabled. 
SELINUX=enforcing 
#SELINUX=disabled 
# SELINUXTYPE= type of policy in use. Possible values are: 
# targeted - Only targeted network daemons are protected. 
# strict - Full SELinux protection. 
SELINUXTYPE=targeted 
#SELINUX有「disabled」「permissive」,「enforcing」3种选择。 
1.模式的设置 
enforcing:强制模式,只要selinux不允许,就无法执行 
permissive:警告模式,将该事件记录下来,依然允许执行 
disabled:关闭selinux;停用,启用需要重启计算机。

2.策略的设置 
targeted:保护常见的网络服务,是selinux的默认值; 
stric:提供RBAC的policy,具备完整的保护功能,保护网络服务,一般指令及应用程序。 
策略改变后,需要重新启动计算机。 
也可以通过命令来修改相关的具体的策略值,也就是修改安全上下文,来提高策略的灵活性。

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 $? 

如果为-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的设置一般通过两个部分完成的,一个是安全上下文,另一个是策略,策略值是对安全上下文的补充。

3.setsebool命令 
setsebool -P allow_ftpd_anon_write=1 
-P 是永久性设置,否则重启之后又恢复预设值。 
示例: 
[root@redhat files]# setsebool -P allow_ftpd_anon_write=1 
[root@redhat files]# getsebool allow_ftpd_anon_write 
allow_ftpd_anon_write --> on 
说明:如果仅仅是安全上下文中设置了vsftpd进程对某一个目录的访问,配置文件中也允许可写,但是selinux中策略中不允许可写,仍然不可写。所以基于selinux保护的服务中,安全性要高于很多。

1.3 SElinux应用 
selinux的设置分为两个部分,修改安全上下文以及策略,下面收集了一些应用的安全上下文,供配置时使用,对于策略的设置,应根据服务应用的特点来修改相应的策略值。 
1.3.1 SElinux与samba 
1.samba共享的文件必须用正确的selinux安全上下文标记。 
chcon -R -t samba_share_t /tmp/abc 
如果共享/home/abc,需要设置整个主目录的安全上下文。 
chcon -R -r samba_share_t /home 
2.修改策略(只对主目录的策略的修改) 
setsebool -P samba_enable_home_dirs=1 
setsebool -P allow_smbd_anon_write=1 
getsebool 查看 
samba_enable_home_dirs -->on 
allow_smbd_anon_write --> on /*允许匿名访问并且可写*/

1.3.2 SElinux与nfs 
selinux对nfs的限制好像不是很严格,默认状态下,不对nfs的安全上下文进行标记,而且在默认状态的策略下,nfs的目标策略允许nfs_export_all_ro 
nfs_export_all_ro 
nfs_export_all_rw值为0 
所以说默认是允许访问的。 
但是如果共享的是/home/abc的话,需要打开相关策略对home的访问。 
setsebool -P use_nfs_home_dirs boolean 1 
getsebool use_nfs_home_dirs

1.3.3 SElinux与ftp 
1.如果ftp为匿名用户共享目录的话,应修改安全上下文。 
chcon -R -t public_content_t /var/ftp 
chcon -R -t public_content_rw_t /var/ftp/incoming

2.策略的设置 
setsebool -P allow_ftpd_anon_write =1 
getsebool allow_ftpd_anon_write 
allow_ftpd_anon_write--> on

1.3.4 SElinux与http 
apache的主目录如果修改为其它位置,selinux就会限制客户的访问。 
1.修改安全上下文: 
chcon -R -t httpd_sys_content_t /home/html 
由于网页都需要进行匿名访问,所以要允许匿名访问。 
2.修改策略: 
setsebool -P allow_ftpd_anon_write = 1 
setsebool -P allow_httpd_anon_write = 1 
setsebool -P allow_<协议名>_anon_write = 1 
关闭selinux对httpd的保护 
httpd_disable_trans=0

1.3.5 SElinux与公共目录共享 
如果ftp,samba,web都访问共享目录的话,该文件的安全上下文应为: 
public_content_t 
public_content_rw_t 
其它各服务的策略的bool值,应根据具体情况做相应的修改。

1.3.6 SElinux配置总结 
以上内容的selinux的配置实验还需要进行相关验证,以便在实际环境中能够直接应用,相关的内容还需要继续补充。 
对于多于牛毛的策略,可以用过滤还查看一个服务相当开启哪些策略。

setsebool命令和设置命令相关推荐

  1. vba mysql 没有为命令对象设置命令_怎样解决“没有为命令对象设置命令”的错误? - .Net论坛 - 51CTO技术论坛_中国领先的IT技术社区...

    复制内容到剪贴板 代码:Private Sub dataQuery_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) H ...

  2. Linux——alias命令(设置命令别名)

    Linux--alias命令(设置命令别名) alias 是shell内建命令(即shell中自带的命令),它可以将常用的命令以及它的参数创建一个别名,来减少命令的输入量 我们常用的一些命令就是别名 ...

  3. linux中mkswap命令使用方法,mkswap命令_Linux mkswap 命令用法详解:建立和设置SWAP交换分区...

    mkswap命令用于在一个文件或者设备上建立交换分区.在建立完之后要使用sawpon命令开始使用这个交换区.最后一个选择性参数指定了交换区的大小,但是这个参数是为了向后兼容设置的,没有使用的必要,一般 ...

  4. Server Core十大安装设置命令

    Server Core作为Windows Server 2008的一个安装选择,被设计用于为核心网络架构提供基础服务,所有不必要的Windows组件都被剔除,它也被视为Windows Server 2 ...

  5. 服务器2003添加共享文档权限,Windows2003使用命令行设置共享权限与安全权限心得...

    Windows2003使用命令行设置共享权限与安全权限心得 Windows2003安装计算机等级考试系统,按系统说明对考试服务器进行安装.在安装过程中,需在服务器上创建大量考试用户和考生文件夹,且需对 ...

  6. OpenCASCADE绘制测试线束:布尔运算命令之设置选项的操作

    OpenCASCADE绘制测试线束:布尔运算命令之设置选项的操作 设置选项的操作 并行处理方式 安全处理模式 模糊选项 粘合选项 bcheckinverted OBB使用 结果简化 绘制警告形状 设置 ...

  7. linux设置共享权限设置命令,Linux系列知识详解(三)--------- Linux链接命令和权限管理命令...

    Linux系列知识详解(三)--------- Linux链接命令和权限管理命令 一:链接命令ln 简介:什么是链接命令?链接命令分为软链接和硬链接.其中软链接产生的新文件是以路径的形式表示原文件,类 ...

  8. dos命令行设置网络优先级_计算机网络故障及其维修方法

    1. 常见计算机网络故障检测.分析能力:掌握计算机网络故障维修方法: 2. 会配置小型计算机网络系统:了解常见计算机网络故障原因:了解计算机网络故障处理方法: 3. 能利用所学知识和经验(灵活性)创造 ...

  9. 命令行查看网卡使用的驱动+跳板机命令行设置静态地址

    命令行查看网卡使用的驱动 lspci -vvv 如果设备信息的没有出现下面两行 Kernel driver in use: nvme     Kernel modules: nvme 说明驱动没安装 ...

  10. Windows2003使用命令行设置共享权限与安全权限心得

    Windows2003使用命令行设置共享权限与安全权限心得 需在服务器上创建大量考试用户和考生文件夹,且需对每个考生文件夹进行不同权限的设置. 由于用户和文件夹的数量较大,采用手工建立和添加的方式,将 ...

最新文章

  1. linux 文件查找及定位
  2. 零基础入门学习Python,这13个Python惯用小技巧一定要收藏
  3. mac os x java_Mac OS X和多个Java版本
  4. 发现几个常用的asp.net MVC Helper 源码
  5. matlab模拟退火最小球覆盖,【模板】模拟退火 费马点以及最小球覆盖
  6. (24)Vue.js组件—组件注册
  7. 计算机怎么把硬盘分成几个,如何把电脑的一个盘的容量分给另外一个盘
  8. mysql yog中文版下载_SQLyog 12
  9. 我本人一直以来犯的错误,在看了 Think In Java 后才抓了出来
  10. 存储过程系列之存储过程返回值总结
  11. 空间目录Tomcat ShutDown出现 Insufficient space for shared memory file:
  12. SQL面试经典题(含答案)
  13. 去除马赛克,有办法了 附运行教程
  14. 突破百度网盘下载限制(大文件直接下载、使用迅雷下载)
  15. 如何在线绘制简单又漂亮的思维导图
  16. 用python画篮球场_如何使用 Python 创建一个 NBA 得分图?
  17. jmeter 压测java代码
  18. 从事计算机编程工作有前途吗,沙坪坝计算机编程培训有前途吗
  19. 安卓linux病毒,如何清除linux病毒
  20. Lightweight and Reliable Decentralized Reward System using Blockchain

热门文章

  1. 程序员揭秘 一些鲜为人知的编程真相
  2. Oracle Database Documentary Library
  3. python数据包pandas_python | 数据分析(二)- Pandas数据包
  4. Netty4.0学习笔记系列之二:Handler的执行顺序
  5. 阿里云服务器 发送邮箱 STMP 25端口 465端口问题 Javamail 25被禁用
  6. MarkDown说明
  7. FireEye实验室在一次水坑式攻击中发现IE 0DAY
  8. 【Foreign】Weed [线段树]
  9. MySQL类型float double decimal的区别
  10. namenode双机热备之操作实践