Permissions and owners
The restorecon command
Resets files to the SELinux label that the policy defines.
Most useful options
-RRecursive: changes the folder and everything inside it-vShows each label change. Repeated, it gives more detail-nChanges nothing, only checks. With -v it shows what would change-FForces the label reset, including the user, role and range parts-iIgnores files that do not existCopy-ready examples
$ sudo restorecon -v /var/www/html/index.htmlrestores the label of one file and tells you whether it changed.$ sudo restorecon -Rvn /var/wwwdry run: lists which files would change, without touching them.$ sudo restorecon -Rv /var/wwwapplies the labels to the whole folder and shows each change.$ sudo restorecon -Rv /srv/webafter creating a rule with semanage fcontext, applies it to the files that already exist.You can try them in the browser terminal: it does not touch your computer.
Common errors
| Message | Cause | Fix |
|---|---|---|
| bash: restorecon: command not found | restorecon comes with the SELinux utilities, common on Fedora and RHEL. It is not there by default on Debian and Ubuntu. | Install your distribution's SELinux utilities, or use restorecon only where SELinux is active. |
Typical mistakes
- It only acts on what is on disk: a new semanage rule does not affect files until you run restorecon.
- With -R it walks the whole folder and may change many files. Use -n first to see what it would touch.
- It does not fix Unix permissions. If the server user cannot read the file because of its permissions, it will keep failing even with the right label.
Differences from similar commands
Related commands
FAQ
What exactly does restorecon do?
It restores the SELinux context of files and folders according to the policy rules.
When do I need it?
After copying or moving files into a path with a different label, or after creating a rule with semanage fcontext. For example, when copying web pages into /var/www.
Does it also restore permissions?
No. It only touches the SELinux context. The rwx permissions are still handled by chmod and chown.
More Permissions and owners commands
Learn to actually use it
The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.
Start the free course