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 todrop
zone wich drop packets.firewall-cmd --zone=drop --remove-source=192.168.122.191/24
β‘ remove determined ip fromdrop
zone.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 abouthome
zone.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 topublic
zone.firewall-cmd --reload
β‘ reload to apply the changes.
Permanently add a Service to a zone:
firewall-cmd --add-service=httpd --zone=public
β‘ add port topublic
zone.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
β‘ givesuser100
read and write permissions onfile1
by using Access Control Lists (ACLs).setfacl -dm u:user100:7,u:user200:rwx projects/
β‘ allocate defaultrwx
permissions touser100
anduser200
onprojects/
dir.setfacl -m m:r file1
β‘ set mask limitiation to onlyread
access onfile1
.getfacl file1 -c
β‘ display ACL properties forfile1
and 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_config
setPermitRootLogin no
β‘ disallow root login via ssh, needssshd
to 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/config
file β‘ 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
β‘ theZ
flag available for some commands asid
,ps
,ls
) allows to view SELinux context.ps auxZ | grep -e http -ei label
β‘ show detailed info about allhttp
named processes running (diplayingps
header).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 directorydir1
recursively.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/files
directory. It relabels, apply the changes.ls -ldZ
β‘ verifiy applied changes.
man semanage-fcontext
β‘ see man page forfcontext
subcommand.semanage fcontext -Cl
β‘ list recent changes in the policy database.--preserve=context
β‘ this flag available forcp
command allows to copy preserving SELinux context for the object.semanage port -at http_port_t -p tcp 8010
β‘ add port8010
with typehttp_port_t
and protocoltcp
, to the policy.semanage port -d -p tcp 8010
β‘ delete port8010
with protocoltcp
from the policy.
RESTORE DEFAULT FILE CONTEXTS
Use
restorecon
to restore file contexts changed temporarily by usingchcon
command! To restore default file contexts changed permanently on files/dirs,semanage fcontext -D
must 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_rw
boolean tooff
.setsebool -P nfs_export_all_rw 0
β‘ persistently setnfs_export_all_rw
boolean 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 bysystemd
journal.ausearch -m AVC,USER_AVC,SELINUX_ERR,USER_SELINUX_ERR -ts recent
β‘ useausearch
tool to query Audit logs.sealert -l 97a1c0df-81ed-4c08-ba27-41c5067b713b
β‘ Display alert event.grep 1415714880.156:29 /var/log/audit/audit.log | audit2why
β‘ useaudit2why
tool 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.