A web administrator moved a new index.html file into /var/www/html/. After the move, users can no longer access the website, receiving a 'Forbidden' error. The administrator checks the standard file permissions, and they appear to be correct. However, running ls -Z /var/www/html/index.html reveals the file has an incorrect SELinux context of unconfined_u:object_r:user_home_t:s0. Which of the following commands should the administrator use to fix the issue by applying the correct, default SELinux context?
semanage fcontext -a -t httpd_sys_content_t '/var/www/html/index.html'
The correct command is restorecon -v /var/www/html/index.html. The restorecon command is used to restore the default SELinux security context for files and directories based on the system's SELinux policy. Since the index.html file was moved from a user's home directory, it retained its user_home_t context, which Apache is not allowed to access. Running restorecon resets the file's context to the appropriate httpd_sys_content_t type, which is defined in the policy for the /var/www/html/ directory, thereby resolving the access issue.
chcon -t httpd_sys_content_t /var/www/html/index.html is incorrect because, while it changes the context, the change is not persistent and will be reverted if the filesystem is relabeled or if restorecon is run on the parent directory.
semanage fcontext -a -t httpd_sys_content_t '/var/www/html/index.html' is incorrect because this command modifies the SELinux policy itself to define a default context. This step is not necessary if the policy already correctly defines the context for /var/www/html/ and is used to set new rules, not to fix a mislabeled file.
setenforce 0 is incorrect as it would switch SELinux into Permissive mode, effectively disabling its protections. While this would make the site accessible, it does not fix the underlying context issue and significantly reduces the system's security.
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 why is it important?
Open an interactive chat with Bash
What is the difference between `restorecon` and `chcon` in SELinux?
Open an interactive chat with Bash
How does SELinux handle file contexts, and why is the `httpd_sys_content_t` type important?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
Security
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
IT & Cybersecurity Package Join Premium for Full Access