chcon β Change SELinux security context of files
| Use Case | Command | Description |
|---|---|---|
| Set a specific security context | chcon CONTEXT FILE | π Assign the given CONTEXT to FILE |
| Copy context from a reference file | chcon --reference=RFILE FILE | π Use RFILE's security context for FILE |
| Recursively change context | chcon -R CONTEXT DIR | π Change context of all files under DIR |
| Set specific components | chcon -u USER -r ROLE -t TYPE -l RANGE FILE | π€ππ·οΈπ Set user, role, type, or range individually |
chcon [OPTION]... CONTEXT FILE...
chcon [OPTION]... [-u USER] [-r ROLE] [-l RANGE] [-t TYPE] FILE...
chcon [OPTION]... --reference=RFILE FILE...
Change the SELinux security context of each FILE to CONTEXT. With --reference, change the security context of each FILE to that of RFILE.
Also see Common options.
--dereference β ποΈ Do not affect symbolic links but what they refer to; this is the default.-h, --no-dereference β π Affect the symbolic links themselves instead of any referenced file.--reference=RFILE β π Use RFILEβs security context rather than specifying a CONTEXT value.-R, --recursive β π Operate on files and directories recursively.--preserve-root β π‘οΈ Refuse to operate recursively on the root directory, /, when used together with --recursive. (See Treating / specially)--no-preserve-root β β οΈ Do not treat the root directory, /, specially when operating recursively; this is the default. (See Treating / specially)-H β β‘οΈ If --recursive (-R) is specified and a command line argument is a symbolic link to a directory, traverse it. (See Traversing symlinks)-L β β‘οΈ In a recursive traversal, traverse every symbolic link to a directory that is encountered. (See Traversing symlinks)-P β π« Do not traverse any symbolic links. This is the default if none of -H, -L, or -P is specified. (See Traversing symlinks)-v, --verbose β π’ Output a diagnostic for every file processed.-u USER, --user=USER β π€ Set user USER in the target security context.-r ROLE, --role=ROLE β π Set role ROLE in the target security context.-t TYPE, --type=TYPE β π·οΈ Set type TYPE in the target security context.-l RANGE, --range=RANGE β π Set range RANGE in the target security context.An exit status of zero indicates success, and a nonzero value indicates failure.
Generated by phpman v4.9.26-1-g511901d · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-27 17:44 @216.73.216.199
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format