How to Linux re apply or restore SELinux security labels context

in Categories , last updated September 18, 2006

Q. How do I set back the file security contexts to specific files or directories under SElinux enabled kernel? I have restored the /wwwdata/domain1, domain2 directories but my security labels are incorrect.

A. If files or directories restored from backup or compied from other source over network/medium you need to restore back SELinux security labels.

Use restorecon command to set file security contexts. This command is primarily used to set the security context (extended attributes) on one or more files. It can be run at any time to correct errors, to add support for new policy, or with the -n option it can just check whether the file contexts are all as you expect.

Type the following command to re-label all the files under the correct security context:
# restorecon -Rv /wwwdata


  • -R: Change files and directories file labels recursively
  • -v: Show changes in file labels.

Read man page of restorecon for more information.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

Share this on (or read 0 comments/add one below):