selinux常用参数

作者&投稿:咸毕 (若有异议请与网页底部的电邮联系)
SELinux三种基本控制模式以及切换方式,以及SELinux的特点~

一,目前系统文件权限的管理有两种:DAC(传统的) 和 MAC(SELINUX) 1
1,传统的文件权限与帐号关系:自主式存取控制, DAC(DISCRETIONARY ACCESS CONTROL, DAC) 1
2,以政策规则订定特定程序读取特定文件:委任式存取控制, MAC 1
【理解】2
二,SELINUX 的运作模式 2
1,【重要原理】SELINUX 是透过 MAC的方式来控管程序, 2
2,查看安全性上下文的命令 2
【重点】在预设的 TARGETED 政策中,IDENTIFY 与 ROLE 栏位基本上是不重要的! 3
三、SELINUX 的启动、关闭与查看 3
1,并非所有的 LINUX DISTRIBUTIONS都支持 SELINUX 的 3
2,查看SELINUX的模式 3
3,查看 SELINUX 的政策 (POLICY)? 3
4,通过配置文件调整SELINUX的参数 3
5,SELINUX 的启动与关闭 4
6,查看已启动程序的TYPE设定

是指恢复档案目录的预设的security Context规格来源:/etc/selinux//contexts/files/目录内的file_contextsfile_contexts.local常用参数如下:-r | -R:包含子目录与其下档案目录-F:恢復使用预设的项目(就算是档案符合存取规范)-v:显示执行过程使用方式:restorecon [FRrv] [-e excludedir ] pathname... ]使用范例如下:restorecon /etc/ntp.confrestorecon -v /etc/ntp.confrestorecon -v -F /etc/ntp.conf手动配置新增恢复规则:1.档案名称/etc/selinux//contexts/files/file_contexts.local2.新增配置范例/var/ftp(/.*)? system_u:object_r:public_content_t3.注意:可以使用semanage程式来维护会比较方便。


了解和配置 SELinux
1. 获取当前 SELinux 运行状态
getenforce
可能返回结果有三种:Enforcing、Permissive 和 Disabled。Disabled 代表 SELinux 被禁用,Permissive 代表仅记录安全警告但不阻止 可疑行为,Enforcing 代表记录警告且阻止可疑行为。
目前常见发行版中,RHEL、CentOS、Fedora 等默认设置为 Enforcing,其余的如 openSUSE 等为 Permissive。
2. 改变 SELinux 运行状态
setenforce [ Enforcing | Permissive | 1 | 0 ]
该命令可以立刻改变 SELinux 运行状态,在 Enforcing 和 Permissive 之间切换,结果保持至关机。一个典型的用途是看看到底是不是 SELinux 导致某个服务或者程序无法运行。若是在 setenforce 0 之后服务或者程序依然无法运行,那么就可以肯定不是 SELinux 导致的。
若是想要永久变更系统 SELinux 运行环境,可以通过更改配置文件 /etc/selinux/config 实现。注意当从 Disabled 切换到 Permissive 或者 Enforcing 模式后需要重启计算机并为整个文件系统重新创建安全标签(touch /.autorelabel && reboot)。
[root@web2 ~]# vim /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 - 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
3. SELinux 运行策略
配置文件 /etc/selinux/config 还包含了 SELinux 运行策略的信息,通过改变变量 SELINUXTYPE 的值实现,该值有两种可能: targeted 代表仅针对预制的几种网络服务和访问请求使用 SELinux 保护,strict 代表所有网络服务和访问请求都要经过 SELinux。
RHEL、CentOS、Fedora 等默认设置为 targeted,包含了对几乎所有常见网络服务的 SELinux 策略配置,已经默认安装并且可以无需修改直接使用。 若是想自己编辑 SELinux 策略,也提供了命令行下的策略编辑器 seedit 以及 Eclipse 下的编辑插件 eclipse-slide 。
4. coreutils 工具的 SELinux 模式
常见的属于 coreutils 的工具如 ps、ls 等等,可以通过增加 Z 选项的方式获知 SELinux 方面的信息。
4.1使用ps获取:
[barlow@web1 ~]$ ps -auxZ |grep httpd |head -5
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ unconfined_u:system_r:httpd_t:s0 apache 1393 0.0 0.2 279648 2272 ? S Jun27 0:01 /usr/sbin/httpd unconfined_u:system_r:httpd_t:s0 apache 1395 0.0 1.5 272964 15528 ? S Jun27 0:02 /usr/sbin/httpd unconfined_u:system_r:httpd_t:s0 apache 1399 0.0 1.7 272964 17828 ? S Jun27 0:02 /usr/sbin/httpd unconfined_u:system_r:httpd_t:s0 apache 1405 0.0 1.2 272964 12732 ? S Jun27 0:02 /usr/sbin/httpd unconfined_u:system_r:httpd_t:s0 apache 1409 0.0 1.4 272968 14784 ? S Jun27 0:03 /usr/sbin/httpd
4.2使用ls获取
[barlow@web1 ~]$ ls -Z /var/www/ drwxrwxrwx. apache barlow unconfined_u:object_r:httpd_sys_script_exec_t:s0 cgi-bin drwxrwxrwx. apache barlow unconfined_u:object_r:httpd_sys_content_t:s0 error drwxrwxrwx. apache barlow unconfined_u:object_r:httpd_sys_content_t:s0 html drwxrwxrwx. apache barlow unconfined_u:object_r:httpd_sys_content_t:s0 icons drwxrwxrwx. apache barlow system_u:object_r:httpd_sys_content_t:s0 lost+found
以此类推,Z 选项可以应用在几乎全部 coreutils 工具里。
5、常用修改有关httpd服务的SELinux策略方法:
如上,ls -Z方法查询到的文件SELinux上下文跟默认要求的不匹配,则服务无法正常使用,如SELinux要求httpd服务的网页目录或文件的上 下文要为httpd_sys_content_t,否则客户端无法访问。
5.1使用chcon修改httpd目录或文件安全上下文:
如nagios服务器的网页目录上下文默认为unconfined_u:object_r:usr_t:s0,则客户端无法访问:
[root@nagios ~]# ll -Z /usr/local/nagios/share/
-rwxrwxr-x. nagios apache system_u:object_r:usr_t:s0 config.inc.php
drwxrwxr-x. nagios apache unconfined_u:object_r:usr_t:s0 contexthelp
drwxrwxr-x. nagios apache unconfined_u:object_r:usr_t:s0 docs
drwxrwxr-x. nagios apache unconfined_u:object_r:usr_t:s0 images
drwxrwxr-x. nagios apache unconfined_u:object_r:usr_t:s0 includes
-rwxrwxr-x. nagios apache system_u:object_r:usr_t:s0 index.html
-rwxrwxr-x. nagios apache system_u:object_r:usr_t:s0 index.php
……以下略……

使用chcon修改/usr/local/nagios/share/目录及其下所有文件安全上下文为unconfined_u:object_r:httpd_sys_content_t
[root@nagios ~]# chcon -R unconfined_u:object_r:httpd_sys_content_t:s0 /usr/local/nagios/share/
查询结果:
[root@nagios ~]# ls -Z /usr/local/nagios/share/
-rwxrwxr-x. nagios apache unconfined_u:object_r:httpd_sys_content_t:s0 config.inc.php
drwxrwxr-x. nagios apache unconfined_u:object_r:httpd_sys_content_t:s0 contexthelp
drwxrwxr-x. nagios apache unconfined_u:object_r:httpd_sys_content_t:s0 docs
drwxrwxr-x. nagios apache unconfined_u:object_r:httpd_sys_content_t:s0 images
drwxrwxr-x. nagios apache unconfined_u:object_r:httpd_sys_content_t:s0 includes
-rwxrwxr-x. nagios apache unconfined_u:object_r:httpd_sys_content_t:s0 index.html
-rwxrwxr-x. nagios apache unconfined_u:object_r:httpd_sys_content_t:s0 index.php
drwxrwxr-x. nagios apache unconfined_u:object_r:httpd_sys_content_t:s0 locale
-rwxrwxr-x. nagios apache unconfined_u:object_r:httpd_sys_content_t:s0 main.html
不用重启httpd服务,客户端就已经可以访问。
5.2使用semanage工具,让httpd支持非标准端口:
semanage工具非常强大,基本能实现所有SELinux配置,但很多时候我们并不知道SELinux错在哪里,在图形界面下有图形化的分析工具,在 终端界面下也有一个功能非常强大的分析工具sealert,但默认情况下,这两个工具都没有被安装,需要先安装semanage和sealert工具:
[root@web2 ~]# yum -y install policycoreutils-python setroubleshoot
注:semanage的使用也可以参见我的另外一篇博文:Selinux管理工具semanage。
默认情况下 Apache 只侦听 80、443等几个端口,若是直接指定其侦听 808 端口的话,会在 service httpd restart 的时候报错:
[root@web2 ~]# service httpd start
正在启动 httpd:(13)Permission denied: make_sock: could not bind to address 0.0.0.0:808
no listening sockets available, shutting down
Unable to open logs [失败]

查看/var/log/messages 文件,可以看到如下这样的错误:
[root@web2 ~]# tail /var/log/messages
Jun 29 10:30:51 web2 setroubleshoot: SELinux is preventing /usr/sbin/httpd from name_bind access on the tcp_socket . For complete SELinux messages. run sealert -l 2ad073a4-7c64-4175-93ff-9d78f75133af
根据提示,运行sealert -l 2ad073a4-7c64-4175-93ff-9d78f75133af,生成SELinux报告如下:
[root@web2 ~]# sealert -l 2ad073a4-7c64-4175-93ff-9d78f75133af
# semanage port -a -t PORT_TYPE -p tcp 808
其中 PORT_TYPE 是以下之一:ntop_port_t, http_cache_port_t, http_port_t, puppet_port_t, jboss_messaging_port_t, jboss_management_port_t。
根据提示,运行semanage port -a -t PORT_TYPE -p tcp 808,此处需将PORT_TYPE替换为 http_port_t
[root@web2 ~]# semanage port -a -t http_port_t -p tcp 808
查询结果:
[root@web2 ~]# semanage port -l|grep http
http_cache_port_t tcp 3128, 8080, 8118, 8123, 10001-10010
http_cache_port_t udp 3130
http_port_t tcp 808, 80, 443, 488, 8008, 8009, 8443 ##可以看到808端口已经加入
pegasus_http_port_t tcp 5988
pegasus_https_port_t tcp 5989
重启服务:
[root@web2 ~]# service httpd start
正在启动 httpd: [确定]
5.3 修改selinux布尔值,允许创建私人网站
若是希望用户可以通过在 ~/www/ 放置文件的方式创建自己的个人网站的话,那么需要在 Apache 策略中允许该操作执行。使用:
[root@web2 ~]# setsebool httpd_enable_homedirs 1
默认情况下 setsebool 的设置只保留到下一次重启之前,若是想永久生效的话,需要添加 -P 参数,比如:
[root@web2 ~]# setsebool -P httpd_enable_homedirs 1
setsebool 是用来切换由布尔值控制的 SELinux 策略的,当前布尔值策略的状态可以通过 getsebool 来获知。 查看与httpd相关的布尔值:
[root@web2 ~]# getsebool -a |grep http
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 --> on
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 --> on
httpd_execmem --> off
httpd_manage_ipa --> off
httpd_read_user_content --> off
httpd_run_stickshift --> 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 --> on
httpd_use_openstack --> off
httpd_verify_dns --> off
named_bind_http_port --> off
以上列举了

1)ls命令
  在命令后加个 -Z 或者加 –context
  [root@python azureus]# ls -Z
  -rwxr-xr-x fu fu user_u:object_r:user_home_t azureus
  -rw-r--r-- fu fu user_u:object_r:user_home_t Azureus2.jar
  -rw-r--r-- fu fu user_u:object_r:user_home_t Azureus.png
  2)chcon
  更改文件的标签
  [root@python tmp]# ls --context test.txt
  -rw-r--r-- root root root:object_r:staff_tmp_t test.txt
  [root@python tmp]# chcon -t etc_t test.txt
  [root@python tmp]# ls -lZ test.txt
  -rw-r--r-- root root root:object_r:etc_t test.txt
  3)restorecon
  当这个文件在策略里有定义是,可以恢复原来的 文件标签。
  4)setfiles
  跟chcon一样可以更改一部分文件的标签,不需要对整个文件系统重新设定标签。
  5)fixfiles
  一般是对整个文件系统的, 后面一般跟 relabel,对整个系统 relabel后,一般我们都重新启动。如果,在根目录下有.autorelabel空文件的话,每次重新启动时都调用 fixfiles relabel
  6)star
  就是tar在SELinux下的互换命令,能把文件的标签也一起备份起来。
  7)cp
  可以跟 -Z, --context=CONTEXT 在拷贝的时候指定目的地文件的security context
  8)find
  可以跟 –context 查特定的type的文件。
  例子:
  find /home/fu/ --context fu:fu_r:amule_t -exec ls -Z {} \:
  9)run_init
  在sysadm_t里手动启动一些如Apache之类的程序,也可以让它正常进行,domain迁移。


求LINUX的详细命令使用?
Linux的常用命令 如果在Linux命令行模式下遇到不会用的命令,你可以打"man [command]"得到该命令的帮助,如果想知道一个命令有哪些参数,可以打command -help来得到。注意:linux中的参数输入形式和dos不一样,在命令后面应该打一个空格,然后打"-",最后再跟一个或多个参数;另外linux下大小写是有...

linux有哪些的必学文件处理命令?
linux入门式必学的文件处理命令,主要有以下几个命令file,mkdir,grep,dd,find,mv。file 1.作用 file通过探测文件内容判断文件类型,使用权限是所有用户。 2.格式 file [options] 文件名 3.[options]主要参数 -v:在标准输出后显示版本信息,并且退出。 -z:探测压缩过的文件类型。 -L:允许符合连接。 4.简单说明 ...

linux线程查看命令linux线程查看
linux查看活跃线程命令?可以执行ps-ef进行查看 linux怎么查看一个进程的所有线程?使用ps命令 常用参数:-a显示所有进程(等价于-e)(utility)-a显示一个终端的所有进程,除了会话引线 -n忽略选择。-d显示所有进程,但省略所有的会话引线(utility)-x显示没有控制终端的进程,同时显示各个命令的具体路径。

Linux常用命令以及解释
1.cd\/home\/fleety\/Diagserver\/log cd到指定的目录 2.tail -f day.log 实时读取指定目录下的日志(一直中,不停止) 3.grep -a 'mdtId' day.log 或 grep -v 'mdtid' day.log 指定条件下查找mdtid文件的记录 4.tar -zcvf day.log.tgz day.log 或 tar -zcvf day....

一般优化linux的内核,需要优化什么参数
Sysctl命令及linux内核参数调整 一、Sysctl命令用来配置与显示在\/proc\/sys目录中的内核参数.如果想使参数长期保存,可以通过编辑\/etc\/sysctl.conf文件来实现。 命令格式: sysctl [-n] [-e] -w variable=value sysctl [-n] [-e] -p (default \/etc\/sysctl.conf) sysctl [-n] [-e] –a 常用参数的意义: ...

Linux下ps命令详解 Linux下ps命令的详细使用方法
ps 的参数非常多, 在此仅列出几个常用的参数并大略介绍含义 -A 列出所有的行程 -w 显示加宽可以显示较多的资讯 -au 显示较详细的资讯 -aux 显示所有包含其他使用者的行程 au(x) 输出格式 :USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND USER: 行程拥有者 PID: pid CPU: 占用的 ...

linux常用命令
1.列出文件清单命令:ls ls命令能够列出当前目录下的所有内容。ls 命令的执行方式为:ls [-选项] [文件名或者目录名]进入到Linux命令行中后,我们至少要知道当前所处的位置有哪些内容,这些信息就可以使用ls命令来获得。在Linux中,ls命令是最常使用的命令之一,因为在命令行下要随时查看目录内容。如果...

Linux下的基本操作和常用命令
五、Linux常用命令A,目录操作1,创建目录mkdir[-p] 目录名称及路径例如,若要在root用户的主目录中创建一个mysoft目录,则实现的命令为:[root@ROOT ~]#mkdir ~\/text1232,删除目录rmdir 要删除的目录及路径名称例如,若要删除 \/srv\/www目录下的images目录,则操作命令为:[root@ROOT ~]#rmdir \/srv\/www\/images3,...

Linux常用命令有哪些
常用的命令有好多啊,你刚开始学,不用特意的去记,用到什么学什么就好了。 当然非要列举,下面列举的100条,是来自百度经验上的。 希望对你有帮助。Linux常用命令大全100条:1,echo “aa” 》 test.txt 和 echo “bb” 》》 test.txt \/\/》将原文件清空,并且内容写入到文件中,》》将内容...

有关于Linux的df命令
linux中df命令的功能是用来检查linux服务器的文件系统的磁盘空间占用情况。可以利用该命令来获取硬盘被占用了多少空间,目前还剩下多少空间等信息。1.命令格式:df [选项] [文件]2.命令功能:显示指定磁盘文件的可用空间。如果没有文件名被指定,则所有当前被挂载的文件系统的可用空间将被显示。默认情况下...

镇海区19520808525: selinux常用参数
璩鸿博尔: 1)ls命令 在命令后加个 -Z 或者加 –context [root@python azureus]# ls -Z -rwxr-xr-x fu fu user_u:object_r:user_home_t azureus -rw-r--r-- fu fu user_u:object_r:user_home_t Azureus2.jar -rw-r--r-- fu fu user_u:object_r:user_home_t Azureus.png 2)chcon 更...

镇海区19520808525: 如何查看,关闭和开启selinux -
璩鸿博尔: 以下介绍一下SELinux相关的工具 /usr/bin/setenforce 修改SELinux的实时运行模式 setenforce 1 设置SELinux 成为enforcing模式 setenforce 0 设置SELinux 成为permissive模式 如果要彻底禁用SELinux 需要在/etc/sysconfig/selinux中设置参数...

镇海区19520808525: 如何关闭linux系统如何关闭selinux -
璩鸿博尔: 一、查看SELinux状态命令:1、/usr/sbin/sestatus -v ##如果SELinux status参数为enabled即为开启状态 SELinux status: enabled2、getenforce ##也可以用这个命令检查 二、关闭SELinux方法:1、临时关闭(不用重启机器):setenforce 0 #设置SELinux 成为permissive模式#setenforce 1 设置SELinux 成为enforcing模式2、修改配置文件需要重启机器:修改/etc/selinux/config 文件 将SELINUX=enforcing改为SELINUX=disabled 重启机器即可.

镇海区19520808525: 如何更改安卓的selinux状态为permissive -
璩鸿博尔: 通过配置文件调整SELinux的参数 [root@www ~]# vi /etc/selinux/config SELINUX=enforcing <==调整 enforcing|disabled|permissive SELINUXTYPE=targeted <==目前仅有 targeted 与 strictSELinux 的启动与关闭 【重要常识】: 上面是预设的政...

镇海区19520808525: SELinux介绍 -
璩鸿博尔: 在Redhat Enterprise Linux 4.0或Fedora Core 2 Linux以上版本的Linux中,有不少用户经常会遇到诸如apache的Permission denied,X windows打不开等等问题,抛开一些常规配置错误外,很大一部分原因是因为激活了SELinux的缘故.什么是...

镇海区19520808525: 如何在开启selinux前提下解决此问题6969 -
璩鸿博尔: 以下介绍一下SELinux相关e69da5e6ba90e799bee5baa631333337613739的工具 /usr/bin/setenforce 修改SELinux的实时运行模式 setenforce 1 设置SELinux 成为enforcing模式 setenforce 0 设置SELinux 成为permissive模式 如果要彻底禁用...

镇海区19520808525: centos selinux 怎么配置支持 -
璩鸿博尔: 可以通过getenforce来获取当前selinux的状态,可以通过setenforce来设置当前selinux的状态.这两个命令修改的状态在重启后会恢复原样,如果要永久设置,需要在/etc/selinux/config中进行设置.

镇海区19520808525: Linux下如何配置vsftp服务器?
璩鸿博尔: 一、检查是否安装了vsftpd, rpm -qa |grep vsftp 二、新建用户 useradd test -g root -d ... 三、设置密码 passwd test # 连续输入两次密码 四、修改SELinux参数 setsebool ftpd_...

镇海区19520808525: selinux是什么 -
璩鸿博尔: SELinux(Security-Enhanced Linux) 是美国国家安全局(NSA)对于强制访问控制的实现,是 Linux® 上最杰出的新安全子系统.NSA是在Linux社区的帮助下开发了一种访问控制体系,在这种访问控制体系的限制下,进程只能访问那些在他的任务中所需要文件.SELinux 默认安装在 Fedora 和 Red Hat Enterprise Linux 上,也可以作为其他发行版上容易安装的包得到. 外文名称:Security-Enhanced Linux 简 称:SELinux 制造单位:美国国家安全局 地 位:Linux历史上最杰出的新安全系统 性 质:强制访问控制(MAC)安全系统

镇海区19520808525: selinux默认策略类型有几种 -
璩鸿博尔: 了解和配置 SELinux 1. 获取当前 SELinux 运行状态 getenforce 可能返回结果有三种:Enforcing、Permissive 和 Disabled.Disabled 代表 SELinux 被禁用,Permissive 代表仅记录安全警告但不阻止 可疑行为,Enforcing 代表记录警告且阻止可疑行...

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网