https://drive.google.com/file/d/1sIFkdzq0hE0mwb7vBF2i4hOJsyQKvgNh/view?usp=sharing
Every file/process has a 4-part context (user:role:type:level):
ls -Z file.txt
# Output: unconfined_u:object_r:user_home_t:s0
# │ │ │ └── Security Level
# │ │ └────────────── Type (most important!)
# │ └──────────────────────── Role
# └──────────────────────────────────── SELinux User
/etc/selinux/targeted/contexts/files/)/home → user_home_t, /tmp → user_tmp_t)chcon# Create test file
touch file.txt
ls -Z file.txt # unconfined_u:object_r:user_home_t:s0
# Change type temporarily
chcon -t httpd_sys_content_t file.txt
ls -Z file.txt # unconfined_u:object_r:httpd_sys_content_t:s0
# Restore original context
restorecon -v file.txt
ls -Z file.txt # Back to user_home_t
# Create directory structure
mkdir -p /tmp/testdir
cal > /tmp/testdir/cal.txt
# Change context recursively
chcon -R -t httpd_sys_content_t /tmp/testdir/
ls -Z /tmp/testdir/cal.txt # Now httpd_sys_content_t
⚠️ Critical Limitation:
chconchanges are temporary—lost on:
- Reboot
restorecon- Filesystem relabel (
/.autorelabel)
semanage fcontext