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 -n option โ€” 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 ๐Ÿ’…

  • -e directory โ€” exclude a directory (repeat the option to exclude more than one directory. Requires full path). yes bestie you can stack these ๐ŸŽ€
  • -f infilename โ€” 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 the security.sehash extended attribute.
  • -m โ€” do not read /proc/mounts to 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 ๐Ÿ’…
  • -o outfilename โ€” 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 -p and -v options 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 -v options increase the verbosity. note that the -v and -p options are mutually exclusive โ€” again, choose one bestie.
  • -W โ€” display warnings about entries that had no matching files by outputting the selabel_stats(3) results.
  • -c โ€” count and display the number of (would be) relabeled files. the exit code will be set to 0 only 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 -print0 option of GNU find produces input suitable for this mode. fr fr, use it with find -print0 and thank me later ๐Ÿซถ
  • -x โ€” prevent restorecon from crossing file system boundaries. stay in your lane, respectfully ๐Ÿ’…
  • -T nthreads โ€” use up to nthreads threads. specify 0 to create as many threads as there are available CPU cores; 1 to 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 ๐Ÿฆ‹

  1. restorecon by default does not operate recursively on directories. paths leading up the final component of the file(s) are canonicalized using realpath(3) before labeling. it's giving "read the room," not "read the whole directory" ๐Ÿ˜Œ
  2. if the pathname specifies the root directory and the -vR or -vr options 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 label FS_RELABEL. big yikes but make it auditable ๐Ÿ‘‘
  3. to improve performance when relabeling file systems recursively (i.e. the -R or -r option is set), the -D option to restorecon will cause it to store a SHA1 digest of the default specfiles set in an extended attribute named security.sehash on each directory specified in pathname ... once the relabeling has been completed successfully. these digests will be checked should restorecon -D be rerun with the same pathname parameters. see selinux_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