chcon命令:修改对象(文件)的安全上下文。比如:用户:角色:类型:安全级别。主要用在selinux中用来更改安全上下文。
命令格式:

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

Linux 命令之chcon的更多相关文章

  1. 《Linux命令学习手册》系列分享专栏

    <Linux命令学习手册>系列分享专栏 <Linux命令学习手册>已整理成PDF文档,点击可直接下载至本地查阅https://www.webfalse.com/read/207 ...

  2. Linux命令——pr

    参考:Linux命令——column 前言 接触这个命令的初衷是我想把一个很长的单列输出设置成多列输出,奈何column的分列输出机制太智障,直到我发现了pr 参数 pr -# 输出指定的列数. -t ...

  3. Linux实战教学笔记04:Linux命令基础

    第四节:Linux命令基础 标签(空格分隔):Linux实战教学笔记 第1章 认识操作环境 root:当前登陆的用户名 @分隔符 chensiqi:主机名 -:当前路径位置 用户的提示符 1.1 Li ...

  4. 像黑客一样使用 Linux 命令行

    前言 之前在博客园看到一篇介绍 IntelliJ IDEA 配置的文章,它里面用的是 gif 动态图片进行展示,我觉得很不错.所以在我今天以及以后的博文中,我也会尽量使用 gif 动图进行展示.制作 ...

  5. 11 个很少人知道但很有用的 Linux 命令

    Linux命令行吸引了大多数Linux爱好者.一个正常的Linux用户一般掌握大约50-60个命令来处理每日的任务.Linux命令和它们的转换对于Linux用户.Shell脚本程序员和管理员来说是最有 ...

  6. Linux命令随笔

    Linux命令总结 man ==命令帮助; help ==命令的帮助(bash的内置命令); ls ==list,查看目录列表; -ld:查看目录权限; -l:(long)长格式显示属性; -F:给不 ...

  7. linux命令在线手册

    下面几个网址有一些 Linux命令的在线手册,而且还是中文的,还可以搜索.非常方便 Linux命令手册 Linux命令大全 Linux中文man在线手册 每日一linux命令

  8. 常用的一些linux命令

    最近接触到一些linux环境部署的事情,下面分享一些最近使用的比较频繁的一些linux命令~ 1.一次性移动多个文件到一个文件夹里 mv  被移动文件名 -t 目标文件夹 如:mv a.txt b.t ...

  9. 测试或运维工作过程中最常用的几个linux命令?

     大家在测试工作过程中,可能会遇到需要你去服务器修改一些配置文件,譬如说某个字段的值是1 则关联老版本,是0则关联新版本,这时候你可能就需要会下vi的命令操作:或者查看session设置的时长,可能需 ...

随机推荐

  1. PHP 16 个编程法则

    HP是最好的编程语言.对于PHP开发者来说,掌握一些编程法则是十分重要的.而在PHP中,以双下划线(__)开头的方法称为魔术方法,它们扮演着非常重要的角色. 常用的魔术方法包括: -__constru ...

  2. erlang使用心跳模式启动shell

    资料http://blog.yufeng.info/archives/2832 借鉴自从http://blog.csdn.net/mycwq/article/details/18306753 测试例子 ...

  3. ZipArchive扩展的使用和Guzzle依赖的安装使用

    在项目开发的过程中,需要去远程下载录音文件 然后保存到自己的项目中,然后再把录音文件压缩打包,最后再下载给用户 1.Guzzle依赖的安装 guzzle官方文档:http://guzzle-cn.re ...

  4. Linux Change The I/O Scheduler For A Hard Disk

    ow do I change the I/O scheduler for a particular hard disk without rebooting my Linux server system ...

  5. 杂项-公司:Netflix百科-un

    ylbtech-杂项-公司:Netflix百科-un Netflix(Nasdaq NFLX) 成立于1997年,是一家在线影片租赁提供商,主要提供Netflix超大数量的DVD并免费递送,总部位于美 ...

  6. LinqHelper连接数据库配置

    LinqHelper连接数据库配置/// <summary> /// Linq通用数据访问类 /// 指定TDataBase来代替后面要使用的数据上下文(指代) /// where:说明指 ...

  7. jQuery Validate自定义验证方法实现方式

    对应调用函数: ( 可以在内部写js/或者外部引入-我是外部引入的文件 )  validate.expand.js // JavaScript Document //检测手机号是否正确 jQuery. ...

  8. 6410中的PWM&nbsp;定时器

    看了OK6410的手册,感觉晕晕的. 需要整理一下思路. 我觉得主要的知道下面这几个内容吧. 1. 定时器的电路结构. 2. 定时器的工作原理是什么.定时器如何来使用.{使用的时序是什么,在时间轴上各 ...

  9. 初次用SqlServer查看本地的Excel文件时需要注意的地方

    日常用到通过SqlServer 读取Excel文件的案例 ,记录下来 文件路径 :C:\Users\Administrator\Desktop\icd10.xls 1.查询语句: SELECT  *F ...

  10. 辽宁工程技术大学校园网(深澜) 叠加小水管提速,多wan叠加负载均衡

    教程没啥大用了.可以直接修改路由器为DHCP自动获取ip,然后直接登录校园网. 昨天晚上尝试了下用潘多拉固件多wan叠加网速,负载均衡,算是提高了速度. 转载请注明出处.教程供参考.本教程不是破解教程 ...