This is part of the independent and unofficial RHCSA Exam Study Guide series providing free π€ resources for prepare for the exam.
This post covers the objectives under the section:
βMANAGE SECURITYβ
It contains two main parts:
- Resources: with links to learn and practice for each objective.
- Cheatsheet: containing some examples of commands and actions performed in each objective (when applied).
π Resources:
CONFIGURE FIREWALL SETTINGS USING FIREWALL-CMD/FIREWALLD
(This objective is also covered in: βmanage basic networking / restrict network access using firewall-cmd/firewallβ)
π RHCSA v8 Practice Session: Configure firewall settings using firewall-cmd/firewalld
π Using firewalld
CREATE AND USE FILE ACCESS CONTROL LISTS
π RHCSA v8 Practice Session: Create and use file access control lists
π Enjoy Better Flexibility in Granting File System Permissions with Access Control Lists (ACLs)
π Secure Files/Directories using ACLs (Access Control Lists) in Linux
CONFIGURE KEY-BASED AUTHENTICATION FOR SSH
π RHCSA v8 Practice Session: Configure key-based authentication for SSH
π Using ssh-keygen and sharing for key-based authentication in Linux
SET ENFORCING AND PERMISSIVE MODES FOR SELINUX
π What is SELinux?
π About SELinux
π RHCSA v8 Practice Session: Set enforcing and permissive modes for SELinux
LIST AND IDENTIFY SELINUX FILE AND PROCESS CONTEXT
π RHCSA v8 Practice Session: List SELinux file and process context / Restore default file contexts
π Understanding SELinux File Labelling and SELinux Context
π Four semanage commands to keep SELinux in enforcing mode
π 4.1. Customizing the SELinux policy for the Apache HTTP server in a non-standard configuration
RESTORE DEFAULT FILE CONTEXTS
- π RHCSA v8 Practice Session: List SELinux file and process context / Restore default file contexts (at 19:30)
USE BOOLEAN SETTINGS TO MODIFY SYSTEM SELINUX SETTINGS
π RHCSA v8 Practice Session: Use boolean settings to modify system SELinux settings
π Linux security: Manipulating SELinux policies with Booleans
π 4.6. Booleans
π Four semanage commands to keep SELinux in enforcing mode
DIAGNOSE AND ADDRESS ROUTINE SELINUX POLICY VIOLATIONS
π Cheatsheet:
CONFIGURE FIREWALL SETTINGS USING FIREWALL-CMD/FIREWALLD
firewall-cmd --list-services --zone public,cat /etc/firewalld/zones/public.xmlβ‘ list allowed services for specific zone.firewall-cmd --reloadβ‘ apply changes.firewall-cmd --add-port "8000-8005/udp" --zone trusted --permanentβ‘ permanently allow protocol on specified port range on trusted zone.firewall-cmd --panic-onβ‘ start panic mode, blocking any access from outside.firewall-cmd --zone=drop --add-source=192.168.122.191/24β‘ add determined ip todropzone wich drop packets.firewall-cmd --zone=drop --remove-source=192.168.122.191/24β‘ remove determined ip fromdropzone.firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=192.168.122.33 drop'β‘ add rich rule to drop packets from determined ip.firewall-cmd --state,systemctl status firewalldβ‘ check if the service is enabled and active.firewall-cmd --get-default-zoneβ‘ display default zone name.firewall-cmd --get-active-zonesβ‘ display active zones.firewall-cmd --get-zonesβ‘ display all available zones.firewall-cmd --set-default-zone=homeβ‘ set default zone tohome.firewall-cmd --list-allβ‘ display information about the defualt zone.firewall-cmd --list-all --zone=homeβ‘ display information abouthomezone.firewall-cmd --list-all-zonesβ‘ list all zones.firewall-cmd --list-servicesβ‘ list allowed services in the current zone.firewall-cmd --list-portsβ‘ list allowed ports in the current zone.firewall-cmd --zone=public --list-servicesβ‘ list allowed services for the specific zone.Permanently add a Port to a zone:
firewall-cmd --add-port 443/tcp --zone=public --permanentβ‘ add port topubliczone.firewall-cmd --reloadβ‘ reload to apply the changes.
Permanently add a Service to a zone:
firewall-cmd --add-service=httpd --zone=publicβ‘ add port topubliczone.firewall-cmd --runtime-to-permanentβ‘ make changes persist.
firewall-cmd --change-interface=enp7s0 --zone=home --permanentβ‘ change specified interface to specified zone.
CREATE AND USE FILE ACCESS CONTROL LISTS
setfacl -m u:user100:6 file1,setfacl -m u:user100:rw file1β‘ givesuser100read and write permissions onfile1by using Access Control Lists (ACLs).setfacl -dm u:user100:7,u:user200:rwx projects/β‘ allocate defaultrwxpermissions touser100anduser200onprojects/dir.setfacl -m m:r file1β‘ set mask limitiation to onlyreadaccess onfile1.getfacl file1 -cβ‘ display ACL properties forfile1and omit headers.setfacl -x u:user100 file1β‘ removes anyuser100β‘ ACL permissions forfile1.setfacl -k projects/β‘ deletes default ACL permissions forprojects/directory.setfacl -b file1β‘ resets ACL permissions forfile1.
CONFIGURE KEY-BASED AUTHENTICATION FOR SSH
ssh-keygenβ‘ start ssh key generator on interactive mode.ssh-keygen -N "" -qβ‘ generate RSA keys without password, on silent mode.ssh-copy-id server20β‘ copy current userβs public key toserver20.On
/etc/ssh/sshd_configsetPermitRootLogin noβ‘ disallow root login via ssh, needssshdto be restarted.tail /var/log/secureβ‘ view ssh remote access logs (ssh server).
SET ENFORCING AND PERMISSIVE MODES FOR SELINUX
getenforceβ‘ displays current mode of operation.setenforce permissiveβ‘ switch the operating mode to permissive temporarily.Edit
/etc/selinux/configfile β‘ to permanently switch SELinux operating mode (survive reboots).seinfo -uβ‘ (requiressetools-console) list SELinux users.semanage login -lβ‘ show mapping between Linux user and SELinux user.semanage port -lβ‘ list records of the port object type.sestatusβ‘ shows SELinux runtime status and Boolean values.
LIST AND IDENTIFY SELINUX FILE AND PROCESS CONTEXT
ls -Zβ‘ theZflag available for some commands asid,ps,ls) allows to view SELinux context.ps auxZ | grep -e http -ei labelβ‘ show detailed info about allhttpnamed processes running (diplayingpsheader).semanage fcontext -l | grep /var/www/htmlβ‘ display SELinux file contexts for files and dirs whose path contains/var/www/html.chcon -vu user_u -t public_content_t dir1 -Rβ‘ temporarily modify SELinux user and type on the directorydir1recursively.Change file context permanently:
ls -ldZβ‘ verifiy SELinux context for the directory.semanage fcontext -a -s user_u -t public_content_t '/dir1(/.*)?'β‘ add dir1 recursively to the policy database.restorecon -Rv dir1β‘ recursively restore default context on files by referencing the files in the/etc/selinux/targeted/contexts/filesdirectory. It relabels, apply the changes.ls -ldZβ‘ verifiy applied changes.
man semanage-fcontextβ‘ see man page forfcontextsubcommand.semanage fcontext -Clβ‘ list recent changes in the policy database.--preserve=contextβ‘ this flag available forcpcommand allows to copy preserving SELinux context for the object.semanage port -at http_port_t -p tcp 8010β‘ add port8010with typehttp_port_tand protocoltcp, to the policy.semanage port -d -p tcp 8010β‘ delete port8010with protocoltcpfrom the policy.
RESTORE DEFAULT FILE CONTEXTS
Use
restoreconto restore file contexts changed temporarily by usingchconcommand! To restore default file contexts changed permanently on files/dirs,semanage fcontext -Dmust be used!Reset file context permanently:
ls -ldZβ‘ verifiy SELinux context for the directory.semanage fcontext -D '/dir1(/.*)?'β‘ delete all local customizations por specified directory, recursively.restorecon -Rv dir1β‘ apply changes.ls -ldZβ‘ verifiy applied changes.
USE BOOLEAN SETTINGS TO MODIFY SYSTEM SELINUX SETTINGS
getsebool -a,sestatus -b,semanage boolean -lβ‘ list SELinux boolean state.setsebool nfs_export_all_rw 0β‘ temporarily setnfs_export_all_rwboolean tooff.setsebool -P nfs_export_all_rw 0β‘ persistently setnfs_export_all_rwboolean tooff.
DIAGNOSE AND ADDRESS ROUTINE SELINUX POLICY VIOLATIONS
sealert -a /var/log/audit/audit.log && sealert -a /var/log/messagesβ‘ Display SELinux policy violations.journalctl -t setroubleshootβ‘ see alert provided bysystemdjournal.ausearch -m AVC,USER_AVC,SELINUX_ERR,USER_SELINUX_ERR -ts recentβ‘ useausearchtool to query Audit logs.sealert -l 97a1c0df-81ed-4c08-ba27-41c5067b713bβ‘ Display alert event.grep 1415714880.156:29 /var/log/audit/audit.log | audit2whyβ‘ useaudit2whytool to help adressing an issue.matchpathcon -V /var/www/html/*β‘ check the context and compare it to the default label for this path.
Next:
(RHCSA) Manage Containers
β¦or back to Red Hat Certified System Administrator (RHCSA) Exam Study Guide
Useful links & references:
Enable Sysadmin (a blog from Red Hat)
Footnotes:
- Follow me on Twitter to get more posts like this and other quick tips in your feed.
- If you have any doubts or tips about this article, Iβd appreciate knowing and discussing it via email.
- Do you have any other Linux tips? Would you like to publish that in this blog? Please send an email to all drops.
- As English is not my native language, I apologize for the errors. Corrections are welcome.
- Contact: contact [@] alldrops [.] info.




