Here are some SELinux configuration commands with examples:
getenforce
: This command is used to check the current status of SELinux enforcement. The output will be either "Enforcing" or "Permissive". Here is an example:
ruby$ getenforce
Enforcing
setenforce
: This command is used to change the SELinux enforcement status. The options are "Enforcing", "Permissive", and "Disabled". Here is an example:
ruby$ sudo setenforce Permissive
semanage
: This command is used to manage SELinux policy modules, file contexts, users, ports, and other configuration options. Here are some examples:
- To add a new port to the SELinux policy:
css$ sudo semanage port -a -t http_port_t -p tcp 8080
- To add a new user to the SELinux policy:
ruby$ sudo semanage user -a -R "staff_r system_r" -s user_u -r s0 -L s0:c0.c1023 jdoe
chcon
: This command is used to change the SELinux context of a file or directory. Here is an example:
shell$ sudo chcon -t httpd_sys_content_t /var/www/html/index.html
seinfo
: This command is used to display detailed information about the SELinux policy on the system, including the policy type, version, and configuration settings. Here is an example:semanage
: This command is used to view detailed information about SELinux policy modules, file contexts, users, ports, and other configuration options. Here are some examples:- To view the SELinux policy for a specific user:
- To view the SELinux context of a file or directory:
getsebool
: This command is used to view the current value of a SELinux boolean setting. Here is an example:seaudit
: This command is used to view SELinux audit logs, which contain detailed information about security-related events on the system. Here is an example:restorecon
: This command is used to restore the default SELinux context of a file or directory. Here is an example:
yaml$ sudo seinfo
Policy Version: v.34
Policy Language Version: v.34
Policy Server Version: v.34
sql$ sudo semanage login -l
Login Name SELinux User MLS/MCS Range Service
__default__ unconfined_u s0-s0:c0.c1023 *
root unconfined_u s0-s0:c0.c1023 *
system_u system_u s0-s0:c0.c1023 *
jdoe user_u s0-s0:c0.c1023 *
less$ ls -Z /var/www/html/index.html
-rw-r--r--. apache apache unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/html/index.html
lua$ sudo getsebool httpd_can_network_connect
httpd_can_network_connect --> off
bash$ sudo seaudit /var/log/audit/audit.log
...
type=AVC msg=audit(1526457005.507:1422): avc: denied { read } for pid=25405 comm="httpd" name="file.txt" dev="dm-0" ino=3994929 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:user_home_t:s0 tclass=file
...
These are just a few examples of SELinux commands that can be used to view detailed information about the SELinux policy and system settings.
css$ sudo restorecon /var/www/html/index.html
Comments
Post a Comment