\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{PeterCeeAU} \pdfinfo{ /Title (linux-rhel-user-management.pdf) /Creator (Cheatography) /Author (PeterCeeAU) /Subject (Linux (RHEL) User Management 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}{393C6B} \definecolor{LightBackground}{HTML}{F2F2F5} \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 (RHEL) User Management Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{PeterCeeAU} via \textcolor{DarkBackground}{\uline{cheatography.com/58333/cs/15427/}}} \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}PeterCeeAU \\ \uline{cheatography.com/peterceeau} \\ \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 September, 2021.\\ Updated 6th September, 2021.\\ 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} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Notice}} \tn \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{This information specifically relates to place of employment, but may be useful elsewhere.% Row Count 2 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.1169 cm} x{9.1531 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{User and Group Management}} \tn % Row 0 \SetRowColor{LightBackground} Action & Command \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} List users configured on local host & `awk -F: '/\textbackslash{}/home/ \{printf "\%s:\%s\textbackslash{}n",\$3,\$1\}' /etc/passwd | sort -n` \tn % Row Count 5 (+ 4) % Row 2 \SetRowColor{LightBackground} List groups configured on local host & `awk -F: -v id="999" '\$3 \textgreater{} id' /etc/group` \tn % Row Count 7 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{For Users, the assumption is that they are non-system users if they have a `/home` directory \newline For Groups, the assumption is that they are non-system groups if gid is greater the 999 \newline Refer to `/etc/login.defs`} \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}{Create User}} \tn % Row 0 \SetRowColor{LightBackground} Create user & `useradd -c "Firstname Lastname" -d /home/{\emph{firstname.lastname.suffix}} -u \textless{}uid\textgreater{} -g \textless{}gid\textgreater{} -m -s /bin/bash {\emph{firstname.lastname.suffix}}` \tn % Row Count 7 (+ 7) % Row 1 \SetRowColor{white} Create user (shorter) & `useradd -c "Firstname Lastname" -u \textless{}uid\textgreater{} -g \textless{}gid\textgreater{} {\emph{firstname.lastname.suffix}}` \tn % Row Count 11 (+ 4) % Row 2 \SetRowColor{LightBackground} Set password & `passwd {\emph{firstname.lastname.suffix}}` \tn % Row Count 13 (+ 2) % Row 3 \SetRowColor{white} Set account aging policy & `chage -M 90 -W 7 -I 30 -d 0 {\emph{firstname.lastname.suffix}}` \tn % Row Count 16 (+ 3) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{where -M maximum number of days between password changes, -W number of days warning before password expires, -I inactive days after password expires that account is locked, -d days since password changed (setting to 0 zero forces password change on next logon)} \tn % Row Count 22 (+ 6) % Row 5 \SetRowColor{white} Expire password\{\{nl\}\}(force~password change) & `chage -d 0 {\emph{firstname.lastname.suffix}}` \tn % Row Count 25 (+ 3) % Row 6 \SetRowColor{LightBackground} Expire password and set account \seqsplit{expiry(for~contractors)} & `chage -d 0 -E {\bf{YYYY-MM-DD}} {\emph{firstname.lastname.suffix}}` \tn % Row Count 28 (+ 3) % Row 7 \SetRowColor{white} List account aging information & `chage -l {\emph{firstname.lastname.suffix}}` \tn % Row Count 30 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{User accounts are in: {\bf{firstname.lastname.accounttype}} format. These 3 variables are used by the user management scripts. Admin User Account are suffixed with {\bf{.nalx}}. \newline Service Accounts are prefixed with {\bf{svc}}. \newline {\bf{uid}} and {\bf{gid}} are maintained in a central location to ensure uniformity across server fleet.} \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}{Account Management}} \tn % Row 0 \SetRowColor{LightBackground} Disable account\{\{nl\}\}(most effective method) & `chage -E0 {\emph{firstname.lastname.suffix}}` \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} Re-enable account & `chage -E1 {\emph{firstname.lastname.suffix}}` \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} Lock account & `usermod -L {\emph{username}}` \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} Check lock status & `grep {\emph{username}} /etc/shadow`\{\{nl\}\}single exclamation mark before encrypted password means account locked \tn % Row Count 13 (+ 6) % Row 4 \SetRowColor{LightBackground} Lock password & `passwd -l {\emph{username}}` \tn % Row Count 15 (+ 2) % Row 5 \SetRowColor{white} Unlock password & `passwd -u {\emph{username}}` \tn % Row Count 17 (+ 2) % Row 6 \SetRowColor{LightBackground} Check password status & `grep {\emph{username}} /etc/shadow`\{\{nl\}\}two exclamation marks before encrypted password means password locked \tn % Row Count 23 (+ 6) % Row 7 \SetRowColor{white} Check whether password ever set & `grep {\emph{username}} /etc/shadow`\{\{nl\}\}two exclamation marks with no encrypted password means password has never been set \tn % Row Count 29 (+ 6) % Row 8 \SetRowColor{LightBackground} Extend account expiry\{\{nl\}\}(for contractors) & `chage -E {\bf{YYYY-MM-DD}} {\emph{firstname.lastname.suffix}}` \tn % Row Count 32 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{The recommended method of securing an account is disabling by using the `chage` command. Locking of accounts by using `usermod` or passwords by using `passwd` commands are not as effective. For example, an account which uses SSH does not use passwords.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{9.3258 cm} x{7.9442 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{List Logged On Users}} \tn % Row 0 \SetRowColor{LightBackground} Show who is logged on & `who` \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} Show who is logged on and what they are doing & `w` \tn % Row Count 4 (+ 3) % Row 2 \SetRowColor{LightBackground} Show list of last logged in users who are "still logged in" & `last -F | grep 'still logged in'` \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} Print name of users currently logged in to local host & `users` \tn % Row Count 10 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{3.1086 cm} x{14.1614 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Non-standard aliases}} \tn % Row 0 \SetRowColor{LightBackground} Alias & Command \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \seqsplit{`lusers`} & `awk -F: '\{ if (\$3 \textgreater{} 999 \&\& \$3 \textless{} 60001) print \$1 \}' /etc/passwd | grep -v {\emph{suffix}} | sort` \tn % Row Count 4 (+ 3) % Row 2 \SetRowColor{LightBackground} \seqsplit{`ladmins`} & `awk -F: '\{ if (\$3 \textgreater{} 999 \&\& \$3 \textless{} 60001) print \$1 \}' /etc/passwd | grep {\emph{suffix}} | sort` \tn % Row Count 7 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{These are functions stored in \seqsplit{`/etc/profile.d/aliases.sh`.} Again, refer to `/etc/login.defs` for {\bf{UID\_MIN}} and {\bf{UID\_MAX}} and {\bf{GID\_MIN}} and {\bf{GID\_MAX}} values} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Get User Information Function}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{`\# get-useraccounts {[}Account Type: ALL|normal|admins|service{]} {[}Output Format:name|description|almostall|csv|table{]} {[}Additional Info: GROUP|nogroup|complete{]}`} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Where group information is collected from corresponding user entry in `/etc/group` and where addition information is collated from `chage` command} \tn % Row Count 7 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Argument order is important (does not use `getopt` or `getopts`). Account Type - ALL (is the default option). Output Format: no specific option required. Additional Info - GROUP info (is the default option).} \tn % Row Count 12 (+ 5) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{`\# get-useraccounts`} \tn % Row Count 13 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{`\# get-useraccounts service csv group`} \tn % Row Count 14 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{`\# get-useraccounts admins tablefull complete`} \tn % Row Count 15 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Based on function listusers / get-useraccounts (expanded version of the above custom functions `lusers` and `ladmins`). The `get-useraccounts` alias is in PowerShell (verb-noun) format so somewhat familiar for Windows Administrators.} \tn % Row Count 20 (+ 5) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{\seqsplit{https://github.com/PeterCeeAU/linux\_user\_management/blob/b473c53e3a9b83dad4246e6d24ae0109fcca7768/listusers}} \tn % Row Count 23 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Could be saved as part of a function file or incorporated into the system alias file \seqsplit{(`/etc/profile.d/aliases.sh`).}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \end{document}