1setfiles(8) SELinux User Command setfiles(8)
2
3
4
6 setfiles - set SELinux file security contexts.
7
8
10 setfiles [-c policy] [-C] [-d] [-l] [-m] [-n] [-e directory] [-E] [-p]
11 [-s] [-v] [-W] [-F] [-I|-D] [-T nthreads] spec_file pathname ...
12
13
15 This manual page describes the setfiles program.
16
17 This program is primarily used to initialize the security context
18 fields (extended attributes) on one or more filesystems (or parts of
19 them). Usually it is initially run as part of the SELinux installation
20 process (a step commonly known as labeling).
21
22 It can also be run at any other time to correct inconsistent labels, to
23 add support for newly-installed policy or, by using the -n option, to
24 passively check whether the file contexts are all set as specified by
25 the active policy (default behavior) or by some other policy (see the
26 -c option).
27
28 If a file object does not have a context, setfiles will write the de‐
29 fault context to the file object's extended attributes. If a file ob‐
30 ject has a context, setfiles will only modify the type portion of the
31 security context. The -F option will force a replacement of the entire
32 context.
33
35 -c check the validity of the contexts against the specified binary
36 policy.
37
38 -C If only relabeling errors are encountered during the file tree
39 walks, exit with status 1 rather than 255.
40
41 -d show what specification matched each file.
42
43 -e directory
44 directory to exclude (repeat option for more than one direc‐
45 tory).
46
47 -E treat conflicting specifications as errors, such as where two
48 hardlinks for the same inode have different contexts.
49
50 -f infilename
51 infilename contains a list of files to be processed. Use “-” for
52 stdin.
53
54 -F Force reset of context to match file_context for customizable
55 files, and the default file context, changing the user, role,
56 range portion as well as the type.
57
58 -h, -? display usage information and exit.
59
60 -i ignore files that do not exist.
61
62 -I ignore digest to force checking of labels even if the stored
63 SHA256 digest matches the specfiles SHA256 digest. The digest
64 will then be updated provided there are no errors. See the NOTES
65 section for further details.
66
67 -D Set or update any directory SHA256 digests. Use this option to
68 enable usage of the security.sehash extended attribute.
69
70 -l log changes in file labels to syslog.
71
72 -m do not read /proc/mounts to obtain a list of non-seclabel mounts
73 to be excluded from relabeling checks. Setting this option is
74 useful where there is a non-seclabel fs mounted with a seclabel
75 fs mounted on a directory below this.
76
77 -n don't change any file labels (passive check).
78
79 -o outfilename
80 Deprecated - This option is no longer supported.
81
82 -p show progress by printing the number of files in 1k blocks un‐
83 less relabeling the entire OS, that will then show the approxi‐
84 mate percentage complete. Note that the -p and -v options are
85 mutually exclusive.
86
87 -q Deprecated and replaced by -v. Has no effect on other options or
88 on program behavior.
89
90 -r rootpath
91 use an alternate root path. Used in meta-selinux for OpenEmbed‐
92 ded/Yocto builds to label files under rootpath as if they were
93 at /
94
95 -s take a list of files from standard input instead of using a
96 pathname from the command line (equivalent to “-f -” ).
97
98 -v show changes in file labels and output any inode association pa‐
99 rameters. Note that the -v and -p options are mutually exclu‐
100 sive.
101
102 -W display warnings about entries that had no matching files by
103 outputting the selabel_stats(3) results.
104
105 -0 the separator for the input items is assumed to be the null
106 character (instead of the white space). The quotes and the
107 backslash characters are also treated as normal characters that
108 can form valid input. This option finally also disables the end
109 of file string, which is treated like any other argument. Use‐
110 ful when input items might contain white space, quote marks or
111 backslashes. The -print0 option of GNU find produces input
112 suitable for this mode.
113
114 -T nthreads
115 use up to nthreads threads. Specify 0 to create as many threads
116 as there are available CPU cores; 1 to use only a single thread
117 (default); or any positive number to use the given number of
118 threads (if possible).
119
120
122 spec_file
123 The specification file which contains lines of the following
124 form:
125
126 regexp [type] context | <<none>>
127 The regular expression is anchored at both ends. The op‐
128 tional type field specifies the file type as shown in the
129 mode field by the ls(1) program, e.g. -- to match only
130 regular files or -d to match only directories. The con‐
131 text can be an ordinary security context or the string
132 <<none>> to specify that the file is not to have its con‐
133 text changed.
134 The last matching specification is used. If there are
135 multiple hard links to a file that match different speci‐
136 fications and those specifications indicate different se‐
137 curity contexts, then a warning is displayed but the file
138 is still labeled based on the last matching specification
139 other than <<none>>.
140
141 pathname ...
142 The pathname for the root directory of each file system to be
143 relabeled or a specific directory within a filesystem that
144 should be recursively descended and relabeled or the pathname of
145 a file that should be relabeled. Not used if the -f or the -s
146 option is used.
147
148
150 setfiles exits with status 0 if it encounters no errors. Fatal errors
151 result in status 255. Labeling errors encountered during file tree
152 walk(s) result in status 1 if the -C option is specified and no other
153 kind of error is encountered, and in status 255 otherwise.
154
155
157 1. setfiles operates recursively on directories. Paths leading up the
158 final component of the file(s) are not canonicalized before label‐
159 ing.
160
161 2. If the pathname specifies the root directory and the -v option is
162 set and the audit system is running, then an audit event is auto‐
163 matically logged stating that a "mass relabel" took place using the
164 message label FS_RELABEL.
165
166 3. To improve performance when relabeling file systems recursively the
167 -D option to setfiles will cause it to store a SHA256 digest of the
168 spec_file set in an extended attribute named security.sehash on
169 each directory specified in pathname ... once the relabeling has
170 been completed successfully. These digests will be checked should
171 setfiles -D be rerun with the same spec_file and pathname parame‐
172 ters. See selinux_restorecon(3) for further details.
173
174 The -I option will ignore the SHA256 digest from each directory
175 specified in pathname ... and provided the -n option is NOT set,
176 files will be relabeled as required with the digests then being up‐
177 dated provided there are no errors.
178
179
181 This man page was written by Russell Coker <russell@coker.com.au>. The
182 program was written by Stephen Smalley <sds@tycho.nsa.gov>
183
184
186 restorecon(8), load_policy(8), checkpolicy(8)
187
188
189
190 10 June 2016 setfiles(8)