restorecon(8)
๐ NAME ๐
bestie, this is restorecon โ it restores file(s) default SELinux security contexts. that's literally its whole job and it ate ๐
โจ SYNOPSIS โจ
restorecon [-r|-R] [-m] [-n] [-p] [-v] [-i] [-F] [-U] [-W] [-I|-D] [-x]
[-e directory] pathname ...
restorecon [-f infilename] [-e directory] [-r|-R] [-m] [-n] [-p] [-v]
[-i] [-F] [-U] [-W] [-I|-D] [-x] [-T nthreads]
๐ธ DESCRIPTION ๐ธ
okay so this is the manual page for the restorecon program, and it is iconic for one specific reason: it sets the security context (those extended attributes, iykyk) on one or more files. periodt ๐
you can also run it literally any other time to:
- correct inconsistent labels (the glow-up your files deserve)
- add support for newly-installed policy
- or โ by using the
-noption โ passively check whether the file contexts are all set as specified by the active policy (that's the default behavior, no cap)
if a file object does not have a context, restorecon will write the default context to the file object's extended attributes. if a file object does have a context, restorecon will only modify the type portion of the security context. the -F and -U options will force a replacement of the entire context โ full reset, main character energy ๐ฅ
if a file is labeled with a customizable SELinux type (for the list of customizable types, see /etc/selinux/{SELINUXTYPE}/contexts/customizable_types), restorecon won't reset the label unless the -F option is used. so don't come for it unless you bring -F ๐
it's the same executable as setfiles but operates in a slightly different manner depending on its argv[0] โ same girl, different vibe check ๐
๐ OPTIONS ๐
-edirectory โ exclude a directory (repeat the option to exclude more than one directory. Requires full path). yes bestie you can stack these ๐-finfilename โ infilename contains a list of files to be processed. use"-"for stdin.-Fโ force reset of context to match file_context for customizable files, and the default file context, changing the user, role, range portion as well as the type. the whole package, slay.-Uโ in addition to the type portion, also change the user and role portions, but not the range portion. picky but make it fashion โจ-h,-?โ display usage information and exit.-iโ ignore files that do not exist. ghost them, respectfully ๐-Iโ ignore digest to force checking of labels even if the stored SHA1 digest matches the specfiles SHA1 digest. the digest will then be updated provided there are no errors. see the NOTES section for further details.-Dโ set or update any directory SHA1 digests. use this option to enable usage of thesecurity.sehashextended attribute.-mโ do not read/proc/mountsto obtain a list of non-seclabel mounts to be excluded from relabeling checks. setting this option is useful where there is a non-seclabel fs mounted with a seclabel fs mounted on a directory below this. lowkey niche but highkey useful ๐ฆ-nโ don't change any file labels (passive check). to display the files whose labels would be changed, add-v. peek, don't touch ๐-ooutfilename โ deprecated โ this option is no longer supported. rip, she's gone ๐ญ-pโ show progress by printing the number of files in 1k blocks unless relabeling the entire OS, that will then show the approximate percentage complete. note that the-pand-voptions are mutually exclusive โ you can't have both, pick your fighter โญ-R,-rโ change files and directories file labels recursively (descend directories). go off, go deep ๐-vโ show changes in file labels. multiple-voptions increase the verbosity. note that the-vand-poptions are mutually exclusive โ again, choose one bestie.-Wโ display warnings about entries that had no matching files by outputting theselabel_stats(3)results.-cโ count and display the number of (would be) relabeled files. the exit code will be set to0only if at least one file is relabeled. no relabels, no zero โ she's strict ๐-0โ the separator for the input items is assumed to be the null character (instead of the white space). the quotes and the backslash characters are also treated as normal characters that can form valid input. this option finally also disables the end of file string, which is treated like any other argument. useful when input items might contain white space, quote marks or backslashes. the-print0option of GNUfindproduces input suitable for this mode. fr fr, use it withfind -print0and thank me later ๐ซถ-xโ preventrestoreconfrom crossing file system boundaries. stay in your lane, respectfully ๐-Tnthreads โ use up to nthreads threads. specify0to create as many threads as there are available CPU cores;1to use only a single thread (default); or any positive number to use the given number of threads (if possible). go parallel bestie ๐ฅ
๐ ARGUMENTS ๐
- pathname ... โ the pathname for the file(s) to be relabeled. yes, plural. she takes many files ๐
๐ฆ NOTES ๐ฆ
restoreconby default does not operate recursively on directories. paths leading up the final component of the file(s) are canonicalized usingrealpath(3)before labeling. it's giving "read the room," not "read the whole directory" ๐- if the pathname specifies the root directory and the
-vRor-vroptions are set and the audit system is running, then an audit event is automatically logged stating that a "mass relabel" took place using the message labelFS_RELABEL. big yikes but make it auditable ๐ - to improve performance when relabeling file systems recursively (i.e. the
-Ror-roption is set), the-Doption torestoreconwill cause it to store a SHA1 digest of the default specfiles set in an extended attribute namedsecurity.sehashon each directory specified in pathname ... once the relabeling has been completed successfully. these digests will be checked shouldrestorecon -Dbe rerun with the same pathname parameters. seeselinux_restorecon(3)for further details. digest girlies, this one's for you ๐ง
the -I option will ignore the SHA1 digest from each directory specified in pathname ... and provided the -n option is NOT set and recursive mode is set, files will be relabeled as required with the digests then being updated provided there are no errors. no cap, read it twice if you have to ๐
๐ EXAMPLE ๐
fix labeling of /var/www/ including all sub-directories and list all context changes
# restorecon -rv /var/www/
list mislabeled files in user home directory and what the correct label should be
# restorecon -nvr ~
fix labeling of files listed in file_list file, ignoring any that do not exist
# restorecon -vif file_list
three commands, three moods, all iconic โจ
๐ AUTHOR ๐
this man page was written by Dan Walsh <dwalsh@redhat.com>. some of the content of this man page was taken from the setfiles man page written by Russell Coker <russell@coker.com.au>. the program was written by Dan Walsh <dwalsh@redhat.com>. legends only ๐
๐ฅ SEE ALSO ๐ฅ
setfiles(8), fixfiles(8), load_policy(8), checkpolicy(8), customizable_types(5)
and that's the whole vibe, bestie ๐ this slay was brought to you by SELinux User Command โ restorecon(8) โ dated 10 June 2016, and she still ate. go forth and relabel responsibly ๐ซถโจ
๐ฆ where this page comes from
- nixos 26.05: policycoreutils 3.11
- nixpkgs unstable: policycoreutils 3.11
- ubuntu stonking: policycoreutils 3.11-1
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms