LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

chcon

change SELinux security context of files

TLDR

View security context of a file
$ ls -lZ path/to/file
copy
Set context using reference file
$ chcon --reference reference_file target_file
copy
Set full context
$ chcon user:role:type:level filename
copy
Change only user component
$ chcon -u user filename
copy
Change only role component
$ chcon -r role filename
copy
Change only type component
$ chcon -t type filename
copy
Change context recursively
$ chcon -R -t type path/to/directory
copy

SYNOPSIS

chcon [OPTION]... CONTEXT FILE...chcon [OPTION]... [-u USER] [-r ROLE] [-t TYPE] [-l RANGE] FILE...chcon [OPTION]... --reference=RFILE FILE...

DESCRIPTION

chcon changes the SELinux security context of files. An SELinux context consists of four components: user, role, type, and range (level). The context can be specified as a complete string, by individual components, or by copying from a reference file.Context changes made with chcon are temporary and will be overwritten during a system relabel or by running restorecon. For persistent context changes, use semanage fcontext to define rules and restorecon to apply them. The chcon command is primarily useful for testing and debugging SELinux policies before making permanent changes.

PARAMETERS

-u, --user=USER

Set the user component of the security context
-r, --role=ROLE
Set the role component of the security context
-t, --type=TYPE
Set the type component of the security context
-l, --range=RANGE
Set the range/level component of the security context
--reference=RFILE
Use security context from RFILE
-R, --recursive
Operate on files and directories recursively
-h, --no-dereference
Affect symbolic links instead of referenced files
--dereference
Affect the referenced file (default for non-links)
-v, --verbose
Output a diagnostic for every file processed
--preserve-root
Fail to operate recursively on /
-H
If -R, follow symbolic links on command line only
-L
If -R, follow all symbolic links
-P
If -R, never follow symbolic links (default)

INSTALL

sudo apt install coreutils
copy
sudo dnf install coreutils
copy
sudo pacman -S coreutils
copy
sudo zypper install coreutils
copy
brew install coreutils
copy
nix profile install nixpkgs#coreutils
copy

CAVEATS

Changes made with chcon are temporary and may be reset by restorecon or system relabeling. For permanent changes, use semanage fcontext and restorecon. SELinux must be enabled for this command to function.

HISTORY

chcon is part of GNU coreutils, providing SELinux security context management for files on systems with SELinux enabled.

SEE ALSO

restorecon(8), semanage(8), ls(1), secon(1)

RESOURCES

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid