How to Linux re apply or restore SELinux security labels context

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.

ADVERTISEMENTS

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

Where,

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

Read man page of restorecon for more information.

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.