[root@kvm5 script]# yum install php
[root@kvm5 ~]# mkdir /var/www/script
[root@kvm5 ~]# cd /var/www/script
[root@kvm5 script]# ls -Zd /{root,bin,dev,etc,home,lib64,proc,tmp,usr,var} lrwxrwxrwx. root root system_u:object_r:bin_t:s0 /bin -> usr/bin drwxr-xr-x. root root system_u:object_r:device_t:s0 /dev drwxr-xr-x. root root system_u:object_r:etc_t:s0 /etc drwxr-xr-x. root root system_u:object_r:home_root_t:s0 /home lrwxrwxrwx. root root system_u:object_r:lib_t:s0 /lib64 -> usr/lib64 dr-xr-xr-x. root root system_u:object_r:proc_t:s0 /proc dr-xr-x---. root root system_u:object_r:admin_home_t:s0 /root drwxrwxrwt. root root system_u:object_r:tmp_t:s0 /tmp drwxr-xr-x. root root system_u:object_r:usr_t:s0 /usr drwxr-xr-x. root root system_u:object_r:var_t:s0 /var
[root@kvm5 script]# mkdir -p {root,dev,etc,home,proc,tmp,usr/{bin,lib64},var} [root@kvm5 script]# ln -s usr/bin bin [root@kvm5 script]# ln -s usr/lib64 lib64
httpd_sys_context
。
[root@kvm5 script]# ls -Z . lrwxrwxrwx. root root unconfined_u:object_r:httpd_sys_content_t:s0 bin -> usr/bin drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 dev drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 etc drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 home lrwxrwxrwx. root root unconfined_u:object_r:httpd_sys_content_t:s0 lib64 -> usr/lib64 drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 proc dr-xr-x---. root root unconfined_u:object_r:httpd_sys_content_t:s0 root drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 tmp drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 usr drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 var
[root@kvm5 script]# for i in bin etc proc tmp usr var > do > semanage fcontext -a -t ${i}_t `pwd`/$i > done [root@kvm5 script]# semanage fcontext -a -t admin_home_t `pwd`/root [root@kvm5 script]# semanage fcontext -a -t lib_t `pwd`/lib64 [root@kvm5 script]# semanage fcontext -a -t home_root_t `pwd`/home [root@kvm5 script]# semanage fcontext -a -t device_t `pwd`/dev
[root@kvm5 script]# restorecon -Rv .
[root@kvm5 script]# ls -Z . lrwxrwxrwx. root root unconfined_u:object_r:bin_t:s0 bin -> usr/bin drwxr-xr-x. root root unconfined_u:object_r:device_t:s0 dev drwxr-xr-x. root root unconfined_u:object_r:etc_t:s0 etc drwxr-xr-x. root root unconfined_u:object_r:home_root_t:s0 home lrwxrwxrwx. root root unconfined_u:object_r:lib_t:s0 lib64 -> usr/lib64 drwxr-xr-x. root root unconfined_u:object_r:proc_t:s0 proc drwxr-xr-x. root root unconfined_u:object_r:tmp_t:s0 tmp drwxr-xr-x. root root unconfined_u:object_r:usr_t:s0 usr drwxr-xr-x. root root unconfined_u:object_r:var_t:s0 var
[root@kvm5 script]# cp --preserve=context \ /bin/{awk,bash,cat,echo,env,grep,mount,sed,sh} bin [root@kvm5 script]# cp --preserve=context \ /usr/bin/{perl,php,python,tee,timeout,tr} usr/bin
[root@kvm5 script]# cp -a --preserve=context -a /usr/{lib64,lib,libexec} usr/
[root@kvm5 script]# stat -c 'major: %t minor: %T' \ /dev/{null,zero,random,urandom} major: 1 minor: 3 major: 1 minor: 5 major: 1 minor: 8 major: 1 minor: 9
[root@kvm5 script]# mknod -m 666 dev/null c 1 3 [root@kvm5 script]# mknod -m 666 dev/zero c 1 5 [root@kvm5 script]# mknod -m 666 dev/random c 1 8 [root@kvm5 script]# mknod -m 666 dev/urandom c 1 9
[root@kvm5 script]# cd dev [root@kvm5 dev]# ls null random urandom zero [root@kvm5 dev]# for i in $(ls) > do > semanage fcontext -a -t ${i}_device_t `pwd`/$i > done
[root@kvm5 dev]# restorecon -v *
[root@kvm5 dev]# ls -Z crw-rw-rw-. root root unconfined_u:object_r:null_device_t:s0 null crw-rw-rw-. root root unconfined_u:object_r:random_device_t:s0 random crw-rw-rw-. root root unconfined_u:object_r:urandom_device_t:s0 urandom crw-rw-rw-. root root unconfined_u:object_r:zero_device_t:s0 zero [root@kvm5 dev]# for i in $(ls) > do semanage fcontext -a -t ${i}_device_t `pwd`/$i > done
[root@kvm5 dev]# cd .. [root@kvm5 script]# chmod 1777 tmp [root@kvm5 script]# ll -Zd tmp/ drwxrwxrwt. root root unconfined_u:object_r:tmp_t:s0 tmp/
[root@kvm5 script]# chroot /var/www/script bash-4.2#
bash-4.2# touch aaa bash: touch: command not found
bash-4.2# exit exit [root@kvm5 script]#