\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{r\_tempest} \pdfinfo{ /Title (linux-general-purpose-cheat-sheet.pdf) /Creator (Cheatography) /Author (r\_tempest) /Subject (Linux General Purpose 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}{02729C} \definecolor{LightBackground}{HTML}{EFF6F8} \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{Linux General Purpose Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{r\_tempest} via \textcolor{DarkBackground}{\uline{cheatography.com/208223/cs/44554/}}} \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}r\_tempest \\ \uline{cheatography.com/r-tempest} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 7th October, 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{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{File, Folders and Permissions management}} \tn % Row 0 \SetRowColor{LightBackground} \{\{width=30\}\}{\bf{Remove file}} & \{\{noshy\}\}rm -f {\bf{{\emph{\textless{}file\textgreater{}}}}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{Remove folder and its contents}} & \{\{noshy\}\}rm -fr {\bf{{\emph{\textless{}folder\textgreater{}}}}} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{Recursively remove files matching regex patterns}} & \{\{noshy\}\}find {\bf{{\emph{\textless{}directory\textgreater{}}}}} -regex '{\bf{{\emph{\textless{}extendend\_regex\textgreater{}}}}}' -exec rm -f \{\} \textbackslash{}; \tn % Row Count 9 (+ 5) % Row 3 \SetRowColor{white} {\bf{Recursively remove files by extension}} & \{\{noshy\}\}find {\bf{{\emph{\textless{}directory\textgreater{}}}}} -iname '*.{\bf{{\emph{\textless{}extension\textgreater{}}}}}' -exec rm -f \{\} \textbackslash{}; \tn % Row Count 13 (+ 4) % Row 4 \SetRowColor{LightBackground} {\bf{Recursively remove files older than N days}} & \{\{noshy\}\}find {\bf{{\emph{\textless{}directory\textgreater{}}}}} -type f -mtime +{\bf{{\emph{\textless{}number\_of\_days\textgreater{}}}}} -exec rm -f \{\} \textbackslash{}; \tn % Row Count 18 (+ 5) % Row 5 \SetRowColor{white} {\bf{Cut or rename files or folders}} & \{\{noshy\}\}mv {\bf{{\emph{\textless{}sources files/folder\textgreater{}}}}} {\bf{{\emph{\textless{}destination folder/file\textgreater{}}}}} \tn % Row Count 22 (+ 4) % Row 6 \SetRowColor{LightBackground} {\bf{Copy files}} & \{\{noshy\}\}cp {\bf{{\emph{\textless{}source files\textgreater{}}}}} {\bf{{\emph{\textless{}destination folder\textgreater{}}}}} \tn % Row Count 25 (+ 3) % Row 7 \SetRowColor{white} {\bf{Copy folders}} & \{\{noshy\}\}cp -r {\bf{{\emph{\textless{}folders\textgreater{}}}}} {\bf{{\emph{\textless{}destination folder\textgreater{}}}}} \tn % Row Count 28 (+ 3) % Row 8 \SetRowColor{LightBackground} {\bf{Change permission of file/folder}} & \{\{noshy\}\}chmod {\bf{{\emph{\textless{}owner\_octal\textgreater{}\textless{}group\_octal\textgreater{}\textless{}other\_octal\textgreater{}}}}} {\bf{{\emph{\textless{}file/folder\textgreater{}}}}} \tn % Row Count 32 (+ 4) \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}{File, Folders and Permissions management (cont)}} \tn % Row 9 \SetRowColor{LightBackground} {\bf{Change permission of folder (Recursively)}} & \{\{noshy\}\}chmod -R {\bf{{\emph{\textless{}owner\_octal\textgreater{}\textless{}group\_octal\textgreater{}\textless{}other\_octal\textgreater{}}}}} {\bf{{\emph{\textless{}folder\textgreater{}}}}} \tn % Row Count 4 (+ 4) % Row 10 \SetRowColor{white} {\bf{Change owner user and group of file/folder}} & chown {\bf{{\emph{\textless{}user\textgreater{}}}}}:{\bf{{\emph{\textless{}group\textgreater{}}}}} {\bf{{\emph{\textless{}file/folder\textgreater{}}}}} \tn % Row Count 7 (+ 3) % Row 11 \SetRowColor{LightBackground} {\bf{Change owner user and group of folder (Recursively)}} & chown -R {\bf{{\emph{\textless{}user\textgreater{}}}}}:{\bf{{\emph{\textless{}group\textgreater{}}}}} {\bf{{\emph{\textless{}folder\textgreater{}}}}} \tn % Row Count 10 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{\textasciicircum{}1\textasciicircum{} Check the octal permissions system at {\bf{Octal Permissions}} session \newline \textasciicircum{}2\textasciicircum{} You can set the maximum search depth when using `find` to remove files with the `-maxdepth N` option. This helps prevent unwanted recursive deletions. For example: `find \textless{}directory\textgreater{} -maxdepth 1 ....`} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.2896 cm} x{8.9804 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Firewalld}} \tn % Row 0 \SetRowColor{LightBackground} \{\{width=30\}\}{\bf{Show all zones}} & \{\{noshy\}\}firewall-cmd -{}-get-zones \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{Show all zones and settings}} & \{\{noshy\}\}firewall-cmd -{}-list-all-zones \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{Allow port at zone}} & \{\{noshy\}\}firewall-cmd -{}-permanent -{}-zone={\bf{{\emph{\textless{}zone\textgreater{}}}}} -{}-add-port={\bf{{\emph{\textless{}port\textgreater{}}}}}/{\bf{{\emph{\textless{}protocol\textgreater{}}}}} \tn % Row Count 9 (+ 5) % Row 3 \SetRowColor{white} {\bf{Reload settings}} & \{\{noshy\}\}firewall-cmd -{}-reload \tn % Row Count 11 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{Allow port from specific network}} & \{\{noshy\}\}firewall-cmd -{}-permanent -{}-zone={\bf{{\emph{\textless{}zone\textgreater{}}}}} -{}-add-rich-rule='rule family="ipv4" source address="{\bf{{\emph{\textless{}network\textgreater{}}}}}" port protocol="{\bf{{\emph{\textless{}protocol\textgreater{}}}}}" port="{\bf{{\emph{\textless{}port\textgreater{}}}}}" accept' \tn % Row Count 21 (+ 10) % Row 5 \SetRowColor{white} {\bf{Remove port from zone}} & firewall-cmd -{}-permanent -{}-zone={\bf{{\emph{\textless{}zone\textgreater{}}}}} -{}-remove-port={\bf{{\emph{\textless{}port\textgreater{}}}}}/{\bf{{\emph{\textless{}protocol\textgreater{}}}}} \tn % Row Count 26 (+ 5) % Row 6 \SetRowColor{LightBackground} {\bf{Remove port from specific network}} & \{\{noshy\}\}firewall-cmd -{}-permanent -{}-remove-rich-rule='rule family="ipv4" source address="{\bf{{\emph{\textless{}network\textgreater{}}}}}" port protocol="{\bf{{\emph{\textless{}protocol\textgreater{}}}}}" port="{\bf{{\emph{\textless{}port\textgreater{}}}}}" accept \tn % Row Count 35 (+ 9) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.2896 cm} x{8.9804 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Firewalld (cont)}} \tn % Row 7 \SetRowColor{LightBackground} {\bf{Allow traffic between interface}} & \{\{noshy\}\}firewall-cmd -{}-permanent -{}-zone={\bf{{\emph{\textless{}zone\textgreater{}}}}} -{}-add-rich-rule='rule family="ipv4" source address="{\bf{{\emph{\textless{}interface\textgreater{}}}}}" accept' \tn % Row Count 7 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{After making any modifications to firewall rules, it is necessary to reload the rules for the changes to take effect.} \tn \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}{Networking}} \tn % Row 0 \SetRowColor{LightBackground} \{\{width=30\}\}{\bf{Check port communication (telnet)}} & \{\{noshy\}\}telnet {\bf{{\emph{\textless{}address\textgreater{}}}}} {\bf{{\emph{\textless{}port\textgreater{}}}}} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{Check port communication (netcat)}} & \{\{noshy\}\}nc -zv {\bf{{\emph{\textless{}address\textgreater{}}}}} {\bf{{\emph{\textless{}port\textgreater{}}}}} \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} {\bf{Open dummy port (netcat)}} & \{\{noshy\}\}nc -lp {\bf{{\emph{\textless{}port\textgreater{}}}}} \tn % Row Count 8 (+ 2) % Row 3 \SetRowColor{white} {\bf{Open TLS/SSL Port (openssl)}} & \{\{noshy\}\}openssl s\_server -accept {\bf{{\emph{\textless{}port\textgreater{}}}}} -cert {\bf{{\emph{\textless{}certificate\_file\textgreater{}}}}} -key {\bf{{\emph{\textless{}key\_file\textgreater{}}}}} \tn % Row Count 13 (+ 5) % Row 4 \SetRowColor{LightBackground} {\bf{Test connection to TLS/SSL Port(openssl)}} & \{\{noshy\}\}openssl s\_client -connect {\bf{{\emph{\textless{}address\textgreater{}}}}}:{\bf{{\emph{\textless{}port\textgreater{}}}}} \tn % Row Count 17 (+ 4) % Row 5 \SetRowColor{white} {\bf{Show TCP IPV4 Listening ports}} & \{\{noshy\}\}ss -ltnp4 | grep {\bf{{\emph{\textless{}port\textgreater{}}}}} \tn % Row Count 19 (+ 2) % Row 6 \SetRowColor{LightBackground} {\bf{Show TCP IPV6 Listening ports}} & \{\{noshy\}\}ss -ltpn6 | grep {\bf{{\emph{\textless{}port\textgreater{}}}}} \tn % Row Count 21 (+ 2) % Row 7 \SetRowColor{white} {\bf{Show all connection and ports}} & \{\{noshy\}\}ss -putona \tn % Row Count 23 (+ 2) % Row 8 \SetRowColor{LightBackground} {\bf{Show interfaces}} & \{\{noshy\}\}ip a \tn % Row Count 24 (+ 1) % Row 9 \SetRowColor{white} {\bf{Show routes}} & \{\{noshy\}\}ip route \tn % Row Count 25 (+ 1) % Row 10 \SetRowColor{LightBackground} {\bf{Show DNS properties}} & \{\{noshy\}\}nslookup {\bf{{\emph{\textless{}DNS\textgreater{}}}}} \tn % Row Count 27 (+ 2) % Row 11 \SetRowColor{white} {\bf{Show ip information}} & \{\{noshy\}\}dig -x {\bf{{\emph{\textless{}ip\textgreater{}}}}} +all \tn % Row Count 29 (+ 2) % Row 12 \SetRowColor{LightBackground} {\bf{Show route to destination}} & \{\{noshy\}\}traceroute {\bf{{\emph{\textless{}ip\textgreater{}}}}} \tn % Row Count 31 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{15.543 cm} p{1.727 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Octal Permissions}} \tn % Row 0 \SetRowColor{LightBackground} \{\{width=30\}\}{\bf{Read}} & 4 \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} {\bf{Write}} & 2 \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} {\bf{Execute}} & 1 \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{For multiple permissions, just add the octal values. Example: read(4) and execute(1) = 5. \newline \newline More about it: \{\{link="https://www.redhat.com/sysadmin/linux-file-permissions-explained"\}\}Linux file permissions explained \{\{/link\}\}} \tn \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}{Remote Access}} \tn % Row 0 \SetRowColor{LightBackground} \{\{width=30\}\}{\bf{Connect via SSH using password}} & ssh -p {\bf{{\emph{\textless{}port\textgreater{}}}}} {\bf{{\emph{\textless{}username\textgreater{}}}}}@{\bf{{\emph{\textless{}hostname/ip\textgreater{}}}}} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{Copy file from local to remote using SCP}} & scp -P {\bf{{\emph{\textless{}port\textgreater{}}}}} {\bf{{\emph{\textless{}local\_file\_path\textgreater{}}}}} {\bf{{\emph{\textless{}username\textgreater{}}}}}@{\bf{{\emph{\textless{}hostname/ip\textgreater{}}}}}:{\bf{{\emph{\textless{}destination folder/file\textgreater{}}}}} \tn % Row Count 9 (+ 6) % Row 2 \SetRowColor{LightBackground} {\bf{Copy file from remote to local using SCP}} & scp -P {\bf{{\emph{\textless{}port\textgreater{}}}}} {\bf{{\emph{\textless{}username\textgreater{}}}}}@{\bf{{\emph{\textless{}hostname/ip\textgreater{}}}}}:{\bf{{\emph{\textless{}file\_path\textgreater{}}}}} {\bf{{\emph{\textless{}destination folder/file\textgreater{}}}}} \tn % Row Count 15 (+ 6) % Row 3 \SetRowColor{white} {\bf{Copy file from local to remote using rsync}} & rsync -avz -e "ssh -p {\bf{{\emph{\textless{}port\textgreater{}}}}}" {\bf{{\emph{\textless{}local file/folder\textgreater{}}}}} {\bf{{\emph{\textless{}username\textgreater{}}}}}@{\bf{{\emph{\textless{}hostname/ip\textgreater{}}}}}:{\bf{{\emph{\textless{}destination folder/file\textgreater{}}}}} \tn % Row Count 22 (+ 7) % Row 4 \SetRowColor{LightBackground} {\bf{Copy file from remote to local using rsync}} & rsync -avz -e "ssh -p {\bf{{\emph{\textless{}port\textgreater{}}}}}" {\bf{{\emph{\textless{}username\textgreater{}}}}}@{\bf{{\emph{\textless{}hostname/ip\textgreater{}}}}}:{\bf{{\emph{\textless{}folder/file\textgreater{}}}}} {\bf{{\emph{\textless{}destination folder/file\textgreater{}}}}} \tn % Row Count 29 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{\textasciicircum{}1\textasciicircum{} Prefer using rsync instead of SCP since it will be deprecated soon. Check references for more information. \newline \textasciicircum{}2\textasciicircum{} For key authentication with SSH, SCP or RSYNC add a `-i {\bf{\textless{}key\_file\textgreater{}}}` after the SSH or SCP command. I.e: `{\emph{ssh -i /home/foo/key.rsa ...}}`. \newline \newline {\bf{References}} \newline \{\{link="https://www.redhat.com/en/blog/openssh-scp-deprecation-rhel-9-what-you-need-know"\}\}OpenSSH SCP deprecation in RHEL 9\{\{/link\}\}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{6.7353 cm} x{10.5347 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{User Management}} \tn % Row 0 \SetRowColor{LightBackground} \{\{width=30\}\}{\bf{Add user}} & useradd -s {\bf{{\emph{\textless{}shell\textgreater{}}}}} -d {\bf{{\emph{\textless{}user\_home\textgreater{}}}}} -m -U {\bf{{\emph{\textless{}username\textgreater{}}}}} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{Add User to Group}} & usermod -aG {\bf{{\emph{\textless{}group\_name\textgreater{}}}}} {\bf{{\emph{\textless{}user\_name\textgreater{}}}}} \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{Remove user from group}} & deluser {\bf{{\emph{\textless{}group\_name\textgreater{}}}}} {\bf{{\emph{\textless{}user\_name\textgreater{}}}}} \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} {\bf{Delete User}} & userdel -f -r {\bf{{\emph{\textless{}user\_name\textgreater{}}}}} \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{Add group}} & groupadd {\bf{{\emph{\textless{}group\_name\textgreater{}}}}} \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} {\bf{Delete group}} & groupdel {\bf{{\emph{\textless{}group\_name\textgreater{}}}}} \tn % Row Count 13 (+ 2) % Row 6 \SetRowColor{LightBackground} {\bf{List user groups}} & groups {\bf{{\emph{\textless{}user\_name\textgreater{}}}}} \tn % Row Count 15 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \end{document}