A systems administrator on a CentOS server recently moved a new index.html file from their home directory to /var/www/html/. When users browse to the site, they receive a "403 Forbidden" error. The administrator verifies that standard file permissions are rw-r--r-- and ownership is correct for the web server process. An ls -Z command reveals the file has an SELinux context of unconfined_u:object_r:user_home_t:s0. Which of the following commands is the BEST method to resolve this issue?
The correct command is restorecon -Rv /var/www/html. When a file is moved, it retains its original SELinux context. In this scenario, the index.html file kept its user_home_t context from the home directory, which the Apache daemon (httpd_t) is not allowed to read. The restorecon command restores the default SELinux file context based on the system's policy rules for the specified path. For /var/www/html, this is typically httpd_sys_content_t, which the web server can access. The -R flag applies this recursively, and -v makes the output verbose. Using chcon would work temporarily but is not best practice as the change would be lost after a system-wide relabel. Disabling SELinux with setenforce 0 would resolve the immediate symptom but would be a poor security practice. The semanage fcontext command is used to add or modify the default context policy itself, which is not necessary here since /var/www/html already has a correct default policy.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is SELinux and how does it relate to file contexts?
Open an interactive chat with Bash
How does the `restorecon` command work in SELinux?
Open an interactive chat with Bash
Why is disabling SELinux with `setenforce 0` not recommended?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
Troubleshooting
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
IT & Cybersecurity Package Join Premium for Full Access