1setfiles(8) SELinux User Command setfiles(8)
2
3
4
6 setfiles - set SELinux file security contexts.
7
8
10 setfiles [-c policy] [-d] [-l] [-m] [-n] [-e directory] [-E] [-p] [-s]
11 [-v] [-W] [-F] [-I|-D] 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
29 default context to the file object's extended attributes. If a file
30 object 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 -d show what specification matched each file (do not abort valida‐
39 tion after 10 errors). Not affected by "-q"
40
41 -e directory
42 directory to exclude (repeat option for more than one direc‐
43 tory).
44
45 -E treat conflicting specifications as errors, such as where two
46 hardlinks for the same inode have different contexts.
47
48 -f infilename
49 infilename contains a list of files to be processed. Use “-” for
50 stdin.
51
52 -F Force reset of context to match file_context for customizable
53 files, and the default file context, changing the user, role,
54 range portion as well as the type.
55
56 -h, -? display usage information and exit.
57
58 -i ignore files that do not exist.
59
60 -I ignore digest to force checking of labels even if the stored
61 SHA1 digest matches the specfiles SHA1 digest. The digest will
62 then be updated provided there are no errors. See the NOTES sec‐
63 tion for further details.
64
65 -D Set or update any directory SHA1 digests. Use this option to
66 enable usage of the security.sehash extended attribute.
67
68 -l log changes in file labels to syslog.
69
70 -m do not read /proc/mounts to obtain a list of non-seclabel mounts
71 to be excluded from relabeling checks. Setting this option is
72 useful where there is a non-seclabel fs mounted with a seclabel
73 fs mounted on a directory below this.
74
75 -n don't change any file labels (passive check).
76
77 -o outfilename
78 Deprecated - This option is no longer supported.
79
80 -p show progress by printing the number of files in 1k blocks
81 unless relabeling the entire OS, that will then show the approx‐
82 imate percentage complete. Note that the -p and -v options are
83 mutually exclusive.
84
85 -q Deprecated, was only used to stop printing inode association
86 parameters.
87
88 -r rootpath
89 use an alternate root path. Used in meta-selinux for OpenEmbed‐
90 ded/Yocto builds to label files under rootpath as if they were
91 at /
92
93 -s take a list of files from standard input instead of using a
94 pathname from the command line (equivalent to “-f -” ).
95
96 -v show changes in file labels and output any inode association
97 parameters. Note that the -v and -p options are mutually exclu‐
98 sive.
99
100 -W display warnings about entries that had no matching files by
101 outputting the selabel_stats(3) results.
102
103 -0 the separator for the input items is assumed to be the null
104 character (instead of the white space). The quotes and the
105 backslash characters are also treated as normal characters that
106 can form valid input. This option finally also disables the end
107 of file string, which is treated like any other argument. Use‐
108 ful when input items might contain white space, quote marks or
109 backslashes. The -print0 option of GNU find produces input
110 suitable for this mode.
111
112
114 spec_file
115 The specification file which contains lines of the following
116 form:
117
118 regexp [type] context | <<none>>
119 The regular expression is anchored at both ends. The
120 optional type field specifies the file type as shown in
121 the mode field by the ls(1) program, e.g. -- to match
122 only regular files or -d to match only directories. The
123 context can be an ordinary security context or the string
124 <<none>> to specify that the file is not to have its con‐
125 text changed.
126 The last matching specification is used. If there are
127 multiple hard links to a file that match different speci‐
128 fications and those specifications indicate different
129 security contexts, then a warning is displayed but the
130 file is still labeled based on the last matching specifi‐
131 cation other than <<none>>.
132
133 pathname ...
134 The pathname for the root directory of each file system to be
135 relabeled or a specific directory within a filesystem that
136 should be recursively descended and relabeled or the pathname of
137 a file that should be relabeled. Not used if the -f or the -s
138 option is used.
139
140
142 1. setfiles operates recursively on directories. Paths leading up the
143 final component of the file(s) are not canonicalized before label‐
144 ing.
145
146 2. If the pathname specifies the root directory and the -v option is
147 set and the audit system is running, then an audit event is auto‐
148 matically logged stating that a "mass relabel" took place using the
149 message label FS_RELABEL.
150
151 3. To improve performance when relabeling file systems recursively the
152 -D option to setfiles will cause it to store a SHA1 digest of the
153 spec_file set in an extended attribute named security.sehash on
154 each directory specified in pathname ... once the relabeling has
155 been completed successfully. These digests will be checked should
156 setfiles -D be rerun with the same spec_file and pathname parame‐
157 ters. See selinux_restorecon(3) for further details.
158
159 The -I option will ignore the SHA1 digest from each directory spec‐
160 ified in pathname ... and provided the -n option is NOT set, files
161 will be relabeled as required with the digests then being updated
162 provided there are no errors.
163
164
166 This man page was written by Russell Coker <russell@coker.com.au>. The
167 program was written by Stephen Smalley <sds@tycho.nsa.gov>
168
169
171 restorecon(8), load_policy(8), checkpolicy(8)
172
173
174
175 10 June 2016 setfiles(8)