chcon命令:修改對象(文件)的安全上下文。好比:用戶:角色:類型:安全級別。主要用在selinux中用來更改安全上下文。
命令格式:html
Chcon [OPTIONS…] CONTEXT FILES…..linux
Chcon [OPTIONS…] –reference=PEF_FILES FILES…安全
說明:服務器
CONTEXT 爲要設置的安全上下文dom
FILES 對象(文件)ui
--reference 參照的對象this
PEF_FILES 參照文件上下文rest
FILES 應用參照文件上下文爲個人上下文。server
OPTIONS 以下:htm
-f 強迫執行
-R 遞歸地修改對象的安全上下文
-r ROLE 修改安全上下文角色的配置
-t TYPE 修改安全上下文類型的配置
-u USER 修改安全上下文用戶的配置
-v 顯示冗長的信息
-l, --range=RANGE 修改安全上下文中的安全級別
範例:
一、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
二、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
三、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
四、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
五、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
六、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
七、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
八、nis
Allow your system to work properly in a NIS environment 系統工做在nis環境時 setsebool -P allow_ypbind 1