CentOS 下设置 SELinux 安全上下文
作用:
chcon 命令用来改变 SELinux 文件属性即修改文件的安全上下文
用法:
chcon [ 选项 ] CONTEXT 文件
选项:
-R:递归改变文件和目录的上下文。
--reference:从源文件向目标文件复制安全上下文
-h, --no-dereference:影响目标链接。
-v, --verbose:输出对每个检查文件的诊断。
-u, --user=USER:设置在目标用户的安全上下文。
-r,--role=ROLE:设置目标安全领域的作用。
-t, --type=TYPE:在目标设定的安全上下文类型。
-l, --range=RANGE:设置 set role ROLE in the target security context 目标安全领域的范围。
-f:显示少量错误信息。
实例:
如果你想把这个ftp共享给匿名用户的话,需要开启以下:
chcon -R -t public_content_t /var/ftp
如果你想让你设置的FTP目录可以上传文件的话,SELINUX需要设置:
chcon -t public_content_rw_t /var/ftp/incoming
允许用户HHTP访问其家目录,该设定限仅于用户的家目录主页:
setsebool -P httpd_enable_homedirs 1 chcon -R -t httpd_sys_content_t ~user/public_html
如果你希望将samba目录共享给其他用户,你需要设置:
chcon -t samba_share_t /directory
共享rsync目录时:
chcon -t public_content_t /directories
chcon命令:修改对象(文件)的安全上下文。比如:用户:角色:类型:安全级别。
命令格式:
Chcon [OPTIONS…] CONTEXT FILES…..
Chcon [OPTIONS…] –reference=PEF_FILES FILES…
说明:
CONTEXT 为要设置的安全上下文
FILES 对象(文件)
--reference 参照的对象
PEF_FILES 参照文件上下文
FILES 应用参照文件上下文为我的上下文。
OPTIONS 如下:
-f 强迫执行
-R 递归地修改对象的安全上下文
-r ROLE 修改安全上下文角色的配置
-t TYPE 修改安全上下文类型的配置
-u USER 修改安全上下文用户的配置
-v 显示冗长的信息
-l, --range=RANGE 修改安全上下文中的安全级别
范例:
1、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
<如果你想让你设置的FTP目录可以上传文件的话,SELINUX需要设置>
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<如果你希望你的FTP用户可以访问自己的家目录的话,需要开启>
setsebool -P ftp_home_dir 1
//If you want to run ftpd as a daemon<如果你希望将vsftpd以daemon的方式运行的话,需要开启>
setsebool -P ftpd_is_daemon 1
//You can disable SELinux protection for the ftpd daemon<你可以让SElinux停止保护vsftpd的daemon方式动行>
setsebool -P ftpd_disable_trans 1
2、httpd
//If you want a particular domain to write to the public_content_rw_t domain
<如果希望具体个doman具有可写权限的话,需要设置>
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 <HTTP被设置允许cgi的设置>
setsebool -P httpd_enable_cgi 1
//If you want to allow access to users home directories<允许用户HHTP访问其家目录,该设定限仅于用户的家目录主页>
setsebool -P httpd_enable_homedirs 1
chcon -R -t httpd_sys_content_t ~user/public_html
//httpd is allowed access to the controling terminal<允许httpd访问终端>
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 <关闭Selinux的关于httpd进程守护的保护>
setsebool -P httpd_disable_trans 1
service httpd restart
3、named
//If you want to have named update the master zone files <关于named,master更新selinux设定>
setsebool -P named_write_master_zones 1
//You can disable SELinux protection for the named daemon by executing
<关闭named的进程守护保护>
setsebool -P named_disable_trans 1
service named restart
4、nfs
//If you want to setup this machine to share nfs partitions read only
<Selinux将本机的NFS共享设置成只读>
setsebool -P nfs_export_all_ro 1
//If you want to share files read/write<Selinux将本机的NFS共享设置成可读可写>
setsebool -P nfs_export_all_rw 1
//If you want to use a remote NFS server for the home directories on this machine
<如果你想要将远程NFS的家目录共享到本机,需要开启>
setsebool -P use_nfs_home_dirs 1
5、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
如果samba服务器共享目录给多个域,则需要:
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
samba服务器要共享家目录时:
setsebool -P samba_enable_home_dirs 1
//If you want to use a remote Samba server for the home directories on this machine
如果你需在本机上使用远程samba服务器的家目录
setsebool -P use_samba_home_dirs 1
//You can disable SELinux protection for the samba daemon by executing
关闭selinux关于samba的进程守护的保护
setsebool -P smbd_disable_trans 1
service smb restart
6、rsync
//If you want to share files using the rsync daemon
共享rsync目录时:
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
停止rsync的进程保护
setsebool -P rsync_disable_trans 1
7、kerberos
//allow your system to work properly in a Kerberos environment
允许系统使用kerberos
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
8、nis
Allow your system to work properly in a NIS environment
系统工作在nis环境时
setsebool -P allow_ypbind 1
CentOS 下设置 SELinux 安全上下文的更多相关文章
- CentOS下设置MySQL的root各种密码 总结
一.更改mysql密码常用的三种方法 大部分情况下,一般用户没有权限更改密码,只有申请了权限或root用户才可以更改密码: 1.方法1:用mysqladmin mysqladmin -u root p ...
- centos下设置自启动和配置环境变量的方法
1. 设置自启动 在CentOS系统下,主要有两种方法设置自己安装的程序开机启动.1.把启动程序的命令添加到/etc/rc.d/rc.local文件中,比如下面的是设置开机启动httpd. #!/bi ...
- Centos 下设置静态ip地址
今天小编遇到了需要设置centos(6.4) 下静态ip地址,下面把详细步骤记录下来. 1> 首先打开这个 vi /etc/sysconfig/network-scripts/ifcfg- ...
- CentOS下设置默认JDK
最近在弄Linux,用yum源安装opnjdk-devel版本后,用命令ll /etc/alternatives/java查看,发现指向的是jre目录,而不是jdk,在此设置指向jdk目录. 1. 设 ...
- centos下设置开机启动程序
首先,设置权限, 由于/etc/rc.local是/etc/rc.d/rc.local的软连接,所以必须确保/etc/rc.local和/etc/rc.d/rc.local都有x权限(可执行) 执行命 ...
- Linux(CentOS)下设置nginx开机自动启动(2个办法)
首先,在linux系统的/etc/init.d/目录下创建nginx文件,使用如下命令: vim /etc/init.d/nginx 在脚本中添加如下命令: #!/bin/sh # # nginx - ...
- centos下设置nodejs开机启动
node环境的安装便不再赘述了,网上有很多教程,也非常简单. 上一篇博客介绍了用nginx代理nodejs.这一篇是使用pm2实现nodejs的自动重启. 什么是pm2? 如官网介绍的,pm2是nod ...
- Centos下设置VNC为3389端口
1.安装vnc yum install vnc vnc-server yum install vnc vnc-server 2.修改vnc端口,修改/usr/bin/vncserver ,把5900变 ...
- CentOS下设置MySQL的root密码
CentOS刚装的MySQL一般需要重设MySQL密码,可以用以下方法重设. 方法一. Js代码 # /etc/init.d/mysqld stop # mysqld_safe --user=my ...
随机推荐
- JAVA集合中的迭代器的遍历
JAVA中的迭代器,迭代实质上就是遍历,在JAVA中使用iterator()方法进行迭代.需要注意的是,iterator()方法的返回值是Iterator对象.Iterator对象有三个方法,hasN ...
- centos7 更新源 安装ifconfig
centos7最小化安装后,ifconfig是不可用的,可以使用ip addr或ip link查看网络信息. 更新源之前,先确定网络是否连通.我用的虚拟机,因为桥接受公司ip限制,换成了NAT模式,确 ...
- TCP与UDP与HTTP协议
http:是用于www浏览的一个协议.tcp:是机器之间建立连接用的到的一个协议. 1.TCP/IP是个协议组,可分为三个层次:网络层.传输层和应用层.在网络层有IP协议.ICMP协议.ARP协议.R ...
- Java中的对象要怎样才算相等
一.引用相等性与对象相等性 1. 引用相等性 引用到堆上同一个对象的两个引用是相等的,这就是引用的相等性. 如果想要知道两个引用是否相等,可以使用==来比较变量上的字节组合,如果引用到相同的对象,字节 ...
- 本地yum源构建以及Docker离线安装
Docker离线安装以及本地yum源构建 在docker的使用过程中有时候会遇到一些私有化部署的问题,就是在一些无法上网的机器上面安装使用dokcer,这就引出了docker的离线安装的问题,dock ...
- Nginx概述、安装及配置详解
nginx概述 nginx是一款自由的.开源的.高性能的HTTP服务器和反向代理服务器:同时也是一个IMAP.POP3.SMTP代理服务器:nginx可以作为一个HTTP服务器进行网站的发布处理,另外 ...
- Android Touch 事件总结
---恢复内容开始--- 1.Touch事件传递机制 过程有点儿类似于栈, ViewGroup的子类有都继承它的以下3个方法: public boolean dispatchTouchEvent(Mo ...
- 【转载】redis.conf文件详解
转载地址:http://blog.csdn.net/zhutulang/article/details/51969760 Redis.conf文件可以在github上查看,下面是我整理的其中的配置项( ...
- left join、right join、inner join、full join
转自:某一网友 left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录inner join ...
- C# 集合的使用List<T>的使用
C# List<T>用法 所属命名空间:using System.Collections.Generic; List<T>类是 ArrayList 类的泛型等效类. 该类使用 ...