What it does
restorecon -Rv PATH compares each file with the policy's file context rules and fixes wrong labels. Use it after semanage fcontext -a, after moving files with mv, or when a service gets "Permission denied" because of a wrong label. -n only shows what would change.
How to write it
restorecon [OPTION]... PATH...
restorecon -f FILE [OPTION]...Options 17
Most used
Nothing matches this filter.
Examples 10
$ run as a normal user# run as root (or with sudo)
1Fix a folder
restorecon -Rv /var/www/html Relabeled /var/www/html/index.html from unconfined_u:object_r:user_home_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0Typical after mv from a home folder.
2Apply a new semanage rule
semanage fcontext -a -t httpd_sys_content_t "/srv/web(/.*)?" restorecon -Rv /srv/webThe rule alone changes nothing on disk.
3Only check
restorecon -Rvn /etcLists files with wrong labels without fixing them.
4Fix one file
restorecon -v /etc/shadowFor example after editing it with a tool that changed the label.
5Fix SSH keys of a user
restorecon -Rv /home/lisa/.sshWrong labels on authorized_keys stop key logins.
6Full system relabel at next boot
After SELinux was disabled, or many wrong labels.
7Find wrongly labeled files for a report (security)
restorecon -Rn -o /root/badlabels.txt /var /srvAudit without changing anything.
8Force full contexts
restorecon -RF /srv/webAlso resets the SELinux user part.
9Many files fast
restorecon -R -T 0 -p /dataAll CPU threads, with progress.
10Check the result
ls -Z /srv/webThe type column.
Nothing matches this filter.
Exit codes
0 :: Done. 255 :: Error.