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?
restorecon -Rv /var/www/html
semanage fcontext -a -t httpd_sys_content_t "/var/www/html/index.html"
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...
Pass with Confidence.
IT & Cybersecurity Package
You have hit the limits of our free tier, become a Premium Member today for unlimited access.
Military, Healthcare worker, Gov. employee or Teacher? See if you qualify for a Community Discount.
Monthly
$19.99
$19.99/mo
Billed monthly, Cancel any time.
3 Month Pass
$44.99
$14.99/mo
One time purchase of $44.99, Does not auto-renew.
MOST POPULAR
Annual Pass
$119.99
$9.99/mo
One time purchase of $119.99, Does not auto-renew.
BEST DEAL
Lifetime Pass
$189.99
One time purchase, Good for life.
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .