restorecon
SafeRestore SELinux labels
restorecon -Rv <path>
Resets file contexts to policy defaults — the proper fix when mv'd files break the web server.
Examples
restorecon -Rv /var/www/htmlFix labels under the web rootls -Z /var/www/htmlShow the current labelsrestorecon -Rnv /var/www/htmlPreview changes only (-n makes no changes)semanage fcontext -a -t httpd_sys_content_t "/data/web(/.*)?" restorecon -Rv /data/webPermanently label a non-default path for web contentausearch -m avc -ts recentRecent SELinux denials
Syntax
restorecon [-R] [-v] <path>
Key points
- cp inherits the label of the destination; mv keeps the original label. That is why files moved with mv become unreadable.
- chcon changes are temporary and restorecon undoes them. Use semanage fcontext for permanent rules.
- If setenforce 0 makes the problem disappear, SELinux is the cause (switch back with setenforce 1).
When it does not work
- If semanage is missing, install policycoreutils-python-utils (policycoreutils-python on older releases).
Before you run it
Relabeling only.
Related commands
- getenforce / sestatusSELinux status
- lsList directory
The same reference, with no signal at all
Every command on this site, held on your device. The app adds 632 more: 1,510 commands and 120 fix flows, searchable with no connection. Free to install, no ads (some content is a one-time purchase).
Get it free on the App Store