\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Bayan (Bayan.A)} \pdfinfo{ /Title (centos-systems-administration-and-security.pdf) /Creator (Cheatography) /Author (Bayan (Bayan.A)) /Subject (CentOS - Systems Administration and Security Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{CentOS - Systems Administration and Security Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Bayan (Bayan.A)} via \textcolor{DarkBackground}{\uline{cheatography.com/122738/cs/44041/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Bayan (Bayan.A) \\ \uline{cheatography.com/bayan-a} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 6th August, 2024.\\ Updated 6th August, 2024.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{tabularx}{17.67cm}{x{7.5988 cm} x{9.6712 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Install Apache / Verify Status}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Install HTTPD service}} & `yum install httpd` \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{Check httpd status}} & `systemctl status httpd.service` \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{7.4261 cm} x{9.8439 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Confirguring Apache HTTP Server}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Inspect Control Script}} & `less \seqsplit{/etc/systemd/system/multi-user}.target.wants/httpd.service` \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} & displays the contents of the httpd.service file for the Apache HTTP server in the systemd multi-user target. \tn % Row Count 8 (+ 5) % Row 2 \SetRowColor{LightBackground} {\bf{Get default start-up state}} & `systemctl get-default` \tn % Row Count 10 (+ 2) % Row 3 \SetRowColor{white} & shows the default target (runlevel) that the system boots into. \tn % Row Count 13 (+ 3) % Row 4 \SetRowColor{LightBackground} {\bf{Find config file}} & `find / -name httpd.conf ` \tn % Row Count 15 (+ 2) % Row 5 \SetRowColor{white} {\bf{Inspect config file}} & `nano \seqsplit{/etc/httpd/conf/httpd.conf`} \tn % Row Count 17 (+ 2) % Row 6 \SetRowColor{LightBackground} & nano {[}location of config file found using `find`{]} \tn % Row Count 20 (+ 3) % Row 7 \SetRowColor{white} {\bf{`.htaccess \& .htpasswd`}} & Note that these are hidden by default, to prevent files being viewed by web clients \tn % Row Count 24 (+ 4) % Row 8 \SetRowColor{LightBackground} {\bf{`ErrorLog`}} & Find and take note of where the errorlog is located (usually `logs/error\_log`) \tn % Row Count 28 (+ 4) % Row 9 \SetRowColor{white} {\bf{`DocumentRoot`}} & The web document location is usually the `/var/www/html` \tn % Row Count 31 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{9.1531 cm} x{8.1169 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Investigate Processes, Make \& Test Apache}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{List processes and filters for those related to httpd}} & `ps -ef $\frac{3}{4}$ grep httpd` \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{Rules for incoming traffic}} & `iptables -L INPUT` \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{Create index.html file}} & 1) Navigate to appropriate directory \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} & e.g.: `cd /var/www/html` \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} & 2) create and edit file using nano \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} & e.g.: `sudo nano index.html` \tn % Row Count 13 (+ 2) % Row 6 \SetRowColor{LightBackground} {\bf{View access log}} & `cat \seqsplit{/var/log/httpd/access\_log`} \tn % Row Count 15 (+ 2) % Row 7 \SetRowColor{white} {\bf{Request local page}} & ` curl http:/localhost ` \tn % Row Count 17 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{MySQL/MariaDB Installation, Start \& Status}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{MariaDB Installation}} & `yum install mariadb-server` \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{Confirm MySQL/MariaDB is installed}} & `find / -name mysql` \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{Start MariaDB}} & `systemctl start mariadb` \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} {\bf{Check MariaDB Status}} & `systemctl status mariadb` \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{Confirm servers are running}} & `ps -ef` \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} & This produces a list of running servers, where you will search for `mysql` in the far left column(the UID(User ID)) \tn % Row Count 16 (+ 6) % Row 6 \SetRowColor{LightBackground} {\bf{Set new password for mysqladmin root}} & `mysqladmin -u root password {[}INSERT PASSWORD{]}` \tn % Row Count 19 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.4623 cm} x{8.8077 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{MySQL Config file \& Data Directory}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Find config file (my.cnf) location}} & `sudo find / -name my.cnf $\frac{3}{4}$ less` \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{Navigate to config file directory}} & `cd {[}INSERT DIRECTORY{]}` \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} & e.g. in my case, my.cnf was located found to be /etc/my.cnf, so `cd /etc` is used \tn % Row Count 9 (+ 5) % Row 3 \SetRowColor{white} {\bf{View contents of config file}} & `cat my.cnf` \tn % Row Count 11 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{Locate MySQL Daemon}} & `find / -name {\emph{mysqld}}` \tn % Row Count 13 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Create \& Populate Database}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Enter MariaDB Server}} & `mysql -h localhost -u root -p` \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} & Then enter password created previously. Note, password will not show any typing. \tn % Row Count 6 (+ 4) % Row 2 \SetRowColor{LightBackground} {\bf{Create database}} & `CREATE DATABASE {[}database name{]}; \tn % Row Count 8 (+ 2) % Row 3 \SetRowColor{white} & e.g. `CREATE DATABASE food;` \tn % Row Count 10 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{Change to created database}} & `USE {[}database{]}` \tn % Row Count 12 (+ 2) % Row 5 \SetRowColor{white} & e.g. `USE food' \tn % Row Count 13 (+ 1) % Row 6 \SetRowColor{LightBackground} {\bf{Exit MariaDB}} & `quit` \tn % Row Count 14 (+ 1) % Row 7 \SetRowColor{white} {\bf{Confirm database was created outside of MariaDB}} & Change to appropriate directory `cd /var/lib/mysql` \tn % Row Count 17 (+ 3) % Row 8 \SetRowColor{LightBackground} & Display contents of current directory using `ls` \tn % Row Count 20 (+ 3) % Row 9 \SetRowColor{white} {\bf{Create Table}} & `CREATE TABLE restaurant (name VARCHAR(40), type VARCHAR(40), location VARCHAR(4));`` \tn % Row Count 25 (+ 5) % Row 10 \SetRowColor{LightBackground} & VARCHAR(n) defines variable length \tn % Row Count 27 (+ 2) % Row 11 \SetRowColor{white} {\bf{Insert values into restaurant table}} & `INSERT INTO restaurant (name, type, location) values ("Pizzahut", "Italian", "SW10");` \tn % Row Count 32 (+ 5) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Create \& Populate Database (cont)}} \tn % Row 12 \SetRowColor{LightBackground} {\bf{Show table}} & `SHOW TABLES; DESCRIBE restaurant; SELECT * FROM restaurant;` \tn % Row Count 4 (+ 4) % Row 13 \SetRowColor{white} {\bf{Delete value from table}} & `DELETE FROM restaurant WHERE \seqsplit{name="Pizza"\&\&location="SW10";`} \tn % Row Count 8 (+ 4) % Row 14 \SetRowColor{LightBackground} {\bf{Create new user}} & `GRANT SELECT ON food.restaurant TO bayan@localhost IDENTIFIED BY \seqsplit{"bayans\_password";`} \tn % Row Count 13 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Firewalls}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Confirm firewalld is running}} & `systemctl status firewalld` \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{Check firewall conifiguration}} & `firewall-cmd -{}-list-all` \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{Display firewall rules}} & `iptables -L' \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} {\bf{Services/ports available for sshd}} & `systemctl status sshd` \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{Services/ports available for httpd}} & `systemctl status httpd` \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} {\bf{Services/ports available for vsftp}} & `systemctl status vsftp` \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} & if not installed, use yum install. e.g. `yum install vsftpd` \tn % Row Count 15 (+ 3) % Row 7 \SetRowColor{white} {\bf{Stop firewalld, then check if running to confirm it is infact stopped}}** & `systemctl stop firewalld` \tn % Row Count 19 (+ 4) % Row 8 \SetRowColor{LightBackground} {\bf{Start firewalld}} & `systemctl start firewalld` \tn % Row Count 21 (+ 2) % Row 9 \SetRowColor{white} {\bf{Add http service to firewall configuration}} & `firewall-cmd -{}-add-service http` \tn % Row Count 24 (+ 3) % Row 10 \SetRowColor{LightBackground} {\bf{Add ftp service to firewall configuration}} & `firewall-cmd -{}-add-service ftp` \tn % Row Count 27 (+ 3) % Row 11 \SetRowColor{white} {\bf{iptables rules for accepting traffic for ports 22(SSH), 80(HTTP), and 21 (FTP)}} & `iptables -A INPUT -p tcp -{}-dport 22 -j ACCEPT` \tn % Row Count 32 (+ 5) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Firewalls (cont)}} \tn % Row 12 \SetRowColor{LightBackground} & `iptables -A INPUT -p tcp -{}-dport 80 -j ACCEPT` \tn % Row Count 3 (+ 3) % Row 13 \SetRowColor{white} & `iptables -A INPUT -p tcp -{}-dport 21 -j ACCEPT` \tn % Row Count 6 (+ 3) % Row 14 \SetRowColor{LightBackground} {\bf{Add rules to output chain}} & `iptables -A OUTPUT -m state -{}-state ESTABLISHED, RELATED -j ACCEPT` \tn % Row Count 10 (+ 4) % Row 15 \SetRowColor{white} {\bf{Dropping default rules for INPUT and OUTPUT traffic}} & `iptables -P INPUT DROP` \tn % Row Count 13 (+ 3) % Row 16 \SetRowColor{LightBackground} & `iptables -P OUTPUT DROP` \tn % Row Count 15 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{SELinux}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Install setroubleshoot and httpd}} & `sudo yum install setroubleshoot httpd` \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{Enable httpd}} & `systemctl enable httpd` \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{Start httpd}} & `systemctl start httpd` \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} {\bf{Check default directory for HTML files}} & `cat \seqsplit{/etc/httpdconf/httpd}.conf | grep DocumentRoot` \tn % Row Count 9 (+ 3) % Row 4 \SetRowColor{LightBackground} {\bf{Check SELinux permissions / context}} & `ls -lZ index.html` \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} {\bf{Temporarily disable SELinux enforcement for troubleshooting or testing without changing the permanent configuration.}} & `setenforce 0` \tn % Row Count 17 (+ 6) % Row 6 \SetRowColor{LightBackground} {\bf{Re-enable SELinux enforcement after it has been disabled, restoring its security policies.}} & `setenforce 1` \tn % Row Count 22 (+ 5) % Row 7 \SetRowColor{white} {\bf{Apply default SELinux to a file:}} & `/sbin/restorecon -v \seqsplit{/var/www/html/secret}.html` \tn % Row Count 25 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \end{document}