LinuxCommandLibrary

semanage-fcontext

Manage persistent SELinux security context rules on files/directories.

TLDR

List all file labelling rules

$ sudo semanage fcontext --list
copy


List all user-defined file labelling rules without headings
$ sudo semanage fcontext --list --locallist --noheading
copy


Add a user-defined rule that labels any path which matches a PCRE regex
$ sudo semanage fcontext --add --type [samba_share_t] ['/mnt/share(/.*)?']
copy


Delete a user-defined rule using its PCRE regex
$ sudo semanage fcontext --delete ['/mnt/share(/.*)?']
copy


Relabel a directory recursively by applying the new rules
$ restorecon -R -v [path/to/directory]
copy

Copied to clipboard