\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{Anthony.Dominguez} \pdfinfo{ /Title (learning-ssh-2.pdf) /Creator (Cheatography) /Author (Anthony.Dominguez) /Subject (Learning SSH 2 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}{154273} \definecolor{LightBackground}{HTML}{F0F3F6} \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{Learning SSH 2 Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Anthony.Dominguez} via \textcolor{DarkBackground}{\uline{cheatography.com/202519/cs/43019/}}} \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}Anthony.Dominguez \\ \uline{cheatography.com/anthony-dominguez} \\ \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 22nd April, 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{multicols*}{2} \begin{tabularx}{8.4cm}{x{1.584 cm} x{0.864 cm} x{1.584 cm} x{3.168 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{8.4cm}}{\bf\textcolor{white}{Installing OpenSSH}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Command}} & {\bf{Options}} & {\bf{Arguments}} & {\bf{Arguments}} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{sudo apt}} & & update & Check for updated package definitions \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} {\bf{sudo apt install}} & & \seqsplit{opens-server} & Install OpenSSH server \tn % Row Count 9 (+ 3) % Row 3 \SetRowColor{white} {\bf{sudo systemctl}} & & status sshd & Information about SSH configuration \tn % Row Count 12 (+ 3) % Row 4 \SetRowColor{LightBackground} {\bf{sudo ufw}} & & status & Check firewall status and rules \tn % Row Count 14 (+ 2) % Row 5 \SetRowColor{white} {\bf{sudo ufw}} & & allow ssh & Allows SSH traffic through the firewall \tn % Row Count 17 (+ 3) % Row 6 \SetRowColor{LightBackground} {\bf{sudo ufw}} & & enable & Enables firewall \tn % Row Count 19 (+ 2) % Row 7 \SetRowColor{white} {\bf{sudo nano}} & & \seqsplit{/etc/ssh/sshd\_config} & Allows editing the SSH server configuration \tn % Row Count 22 (+ 3) % Row 8 \SetRowColor{LightBackground} {\bf{sudo nano}} & & \seqsplit{/etc/ssh/ssh\_config} & Allows editing the SSH client configuration \tn % Row Count 25 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}----} \SetRowColor{LightBackground} \mymulticolumn{4}{x{8.4cm}}{By default, SSH runs in port 22 using TCP protocol \newline SSH server configuration is stored in /etc/ssh/sshd\_config. \newline SSH client configuration is stored in /etc/ssh/ssh\_config.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}----} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{1.672 cm} x{1.9 cm} x{4.028 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Managing Users and Access}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Command}} & {\bf{Argument}} & {\bf{Description}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{AllowUser}} & leigh vishal stefan & Only allow these users to log in \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{DenyUser}} & bob mary paulina & Allow all users except these \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} {\bf{AllowGroup}} & admins \seqsplit{developers} & Only allow users in these groups to log in \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{DenyGroup}} & sales marketing & Allow all users except those in this groups \tn % Row Count 11 (+ 3) % Row 5 \SetRowColor{white} {\bf{Match Address}} & \seqsplit{10.0.1.0/24} & To be able to connect remotely only from 10.0.1.0/24 addresses \tn % Row Count 14 (+ 3) % Row 6 \SetRowColor{LightBackground} {\bf{Match User}} & alice bob & Alice and bob are able to connect remotely according to subsequent parameters \tn % Row Count 18 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{8.4cm}}{All the information above is available in the file /etc/ssh/sshd\_config \newline Precedence matters when defining access} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{1.292 cm} x{2.736 cm} x{3.572 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Connecting to a server using a password}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Command}} & {\bf{Arguments}} & {\bf{Description}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{ssh}} & {\emph{username}}@{\emph{ip address}} & Connect to a remote SSH server \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{8.4cm}}{The first time connection is established to a remote SSH server, a host fingerprint is indicated in the screen, and if the fingerprint is accepted, the local device saves the fingerprint together with information about the connection into a folder into the file /home/ssh/known\_hosts} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.76 cm} x{4.24 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Creating a key pair with ssh-keygen}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Command}} & **Description \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} {\bf{ssh-keygen}} & Generate public/private rsa key pair. \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{ssh-keyscan}} {\emph{server ip address}} & Displays keys to share depending on the encryption algorithm to be used. \tn % Row Count 7 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{It is recommended to generate a key pair for only one purpose (one user/one server). It is also recommended to save the keys in separate folders in the /home/{\emph{user}}/.ssh/ directory. A passphrase can also be added as an extra layer of security for the key pair.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Managing and using key pairs}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Command}} & {\bf{Description}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} ssh-copy-id -i \textasciitilde{}/.ssh/{\emph{mykey}}.pub {\emph{user}}@{\emph{server}} & Add key to \textasciitilde{}/.ssh/authorized\_keys if access to ssh server already exists \tn % Row Count 5 (+ 4) % Row 2 \SetRowColor{LightBackground} Add key to \textasciitilde{}/.ssh/authorized\_keys out of band & Add key to \textasciitilde{}/.ssh/authorized\_keys if access to ssh server does not exists \tn % Row Count 9 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{When changing the configuration of \textasciitilde{}/etc/ssh/sshd\_config with nano, remember to restart the service for the new settings to apply, with {\bf{sudo systemctl restart}} sshd. \newline When having a lot of keys, we can speed up the connection process by specifying which key we want to use to connect to the server, like: {\bf{ssh}} {\emph{user}}@{\emph{server}} -i \textasciitilde{}/.ssh/{\emph{key directory}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{0.8 cm} x{7.2 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Client Configuration Options}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Host {\emph{name}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} & Hostname {\emph{ip address}} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} & Port {\emph{port number}} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} & User {\emph{username}} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} & IdentityFile \textasciitilde{}/.ssh/{\emph{key name}} \tn % Row Count 5 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{For information about precedence's and priorities, consult {\bf{man}} ssh\_config. SSH obtains configuration data from the following sources in the following order: \newline 1. command-line options \newline 2. user's configuration file (\textasciitilde{}/.ssh/config) \newline 3. system-wide configuration file (/etc/ssh/ssh\_config) \newline \newline It is also good practice to change \textasciitilde{}/.ssh/config to be only read and write by the user with {\bf{chmod}} 600 \textasciitilde{}/.ssh/config} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{0.936 cm} x{1.152 cm} x{1.656 cm} x{3.456 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{8.4cm}}{\bf\textcolor{white}{Transferring Files with SFTP}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Command}} & {\bf{Option(s)}} & {\bf{Argument(s)}} & {\bf{Description}} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{sftp}} & & {\emph{user}}@{\emph{ip address}} & Initiate SFTP connection with remote server. \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} {\bf{bye}} & & & Terminates SFTP connection to remote server. \tn % Row Count 9 (+ 3) % Row 3 \SetRowColor{white} {\bf{help}} & & & Shows a list of available commands while in SFTP mode, including commands to change working directories. \tn % Row Count 15 (+ 6) % Row 4 \SetRowColor{LightBackground} {\bf{put}} & & {\emph{file name}} & Sends a file from the local working directory to the remote local directory. \tn % Row Count 19 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}----} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{0.864 cm} x{0.864 cm} x{2.736 cm} x{2.736 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{8.4cm}}{\bf\textcolor{white}{Transferring Files with SCP}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{{\emph{Command}}}} & {\bf{Option(s)}} & {\bf{Argument(s)}} & {\bf{Description}} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} {\bf{scp}} & & {\emph{local file name}} {\emph{user}}@{\emph{ip address}}: & Copies a file from the local working directory to the remote working directory. \tn % Row Count 10 (+ 6) % Row 2 \SetRowColor{LightBackground} {\bf{scp}} & & {\emph{user}}@{\emph{ip address}}:{\emph{remote file name}} {\emph{local file name}} & Copies a file from the remote working directory to the local working directory. \tn % Row Count 16 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}----} \SetRowColor{LightBackground} \mymulticolumn{4}{x{8.4cm}}{The colon represents the remote user home directory, and both relative and absolute paths can be used to refer to a different directory than the home directory.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}----} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{0.72 cm} x{2.016 cm} x{2.232 cm} x{2.232 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{8.4cm}}{\bf\textcolor{white}{Multi-Step SSH Connections}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Command}} & {\bf{Option(s)}} & {\bf{Argument(s)}} & {\bf{Description}} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{ssh}} & -J & {\emph{user}}@{\emph{server1}},{\emph{user}}@{\emph{server2}} {\emph{user}}@{\emph{server3}} & Enable multi-step SSH connection by providing the credentials to all \seqsplit{intermediate} and the final server to be accessed, without manually \seqsplit{establishing} all connections separately. \tn % Row Count 18 (+ 15) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{4}{x{8.4cm}}{} \tn % Row Count 18 (+ 0) % Row 3 \SetRowColor{white} \mymulticolumn{4}{x{8.4cm}}{Host myserver} \tn % Row Count 19 (+ 1) % Row 4 \SetRowColor{LightBackground} & Hostname {\emph{ip address}} & & \tn % Row Count 21 (+ 2) % Row 5 \SetRowColor{white} & Port {\emph{port number}} & & \tn % Row Count 23 (+ 2) % Row 6 \SetRowColor{LightBackground} & User {\emph{username}} & & \tn % Row Count 25 (+ 2) % Row 7 \SetRowColor{white} & \seqsplit{IdentityFile} \textasciitilde{}/.ssh/{\emph{key name}} & & \tn % Row Count 28 (+ 3) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{4}{x{8.4cm}}{} \tn % Row Count 28 (+ 0) % Row 9 \SetRowColor{white} \mymulticolumn{4}{x{8.4cm}}{Host server2} \tn % Row Count 29 (+ 1) % Row 10 \SetRowColor{LightBackground} & Hostname {\emph{ip address}} & & \tn % Row Count 31 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{p{0.72 cm} x{2.016 cm} x{2.232 cm} x{2.232 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{8.4cm}}{\bf\textcolor{white}{Multi-Step SSH Connections (cont)}} \tn % Row 11 \SetRowColor{LightBackground} & ProxyJump {\emph{user}}@{\emph{ip address of myserver}} & & \tn % Row Count 4 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}----} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{1.224 cm} x{0.864 cm} x{2.52 cm} x{2.592 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{8.4cm}}{\bf\textcolor{white}{Port Forwarding with SSH}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Command}} & {\bf{Option(s)}} & {\bf{Argument(s)}} & {\bf{Description}} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} {\bf{ssh}} & -L & {\emph{{[}bind\_addr:{]}}}{\emph{port}}:{\emph{host}}:{\emph{port}} {\emph{user}}@{\emph{ip address}} & Local port forwarding. \tn % Row Count 8 (+ 4) % Row 2 \SetRowColor{LightBackground} {\bf{ssh}} & -R & {\emph{{[}bind\_addr:{]}}}{\emph{port}}:{\emph{host}}:{\emph{port}} & Remote port forwarding. \tn % Row Count 11 (+ 3) % Row 3 \SetRowColor{white} {\bf{ssh}} & -D & {\emph{{[}bind\_addr:{]}}}{\emph{port}} & Dynamic port forwarding. \tn % Row Count 13 (+ 2) % Row 4 \SetRowColor{LightBackground} & -f & & Fork the SSH process into the background \tn % Row Count 16 (+ 3) % Row 5 \SetRowColor{white} & -n & & Don't read from STDIN. \tn % Row Count 18 (+ 2) % Row 6 \SetRowColor{LightBackground} & -N & & Don't run remote commands. \tn % Row Count 20 (+ 2) % Row 7 \SetRowColor{white} & -T & & Don't allocate a TTY \tn % Row Count 22 (+ 2) % Row 8 \SetRowColor{LightBackground} {\bf{ps x}} | {\bf{grep}} & & ssh & Find processes owned by the user, including those without a controlling terminal \tn % Row Count 28 (+ 6) % Row 9 \SetRowColor{white} {\emph{kill}} & & {\emph{process port}} & Ends the process that belongs to a process port. \tn % Row Count 32 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}----} \SetRowColor{LightBackground} \mymulticolumn{4}{x{8.4cm}}{Port forwarding can also be configured in the client file \textasciitilde{}/.ssh/config \newline ... \newline Host server1 \newline \textbackslash{}t{\bf{Hostname}} 10.0.1.110 \newline \textbackslash{}t\# Access remote port 3306 through local port 3333 \newline \textbackslash{}t{\bf{LocalForward}} 3333:localhost:3306 \newline \textbackslash{}t\# Access local port 22 through remote port 5432 \newline \textbackslash{}t{\bf{RemoteForward}} 22:localhost:5432 \newline \textbackslash{}t\# Starts a SOCKS proxy on local port 3000 \newline \textbackslash{}t{\bf{DynamicForward}} 3000} \tn \hhline{>{\arrayrulecolor{DarkBackground}}----} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{1.368 cm} x{1.08 cm} x{1.296 cm} x{3.456 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{8.4cm}}{\bf\textcolor{white}{Troubleshooting SSH}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{{\emph{Command}}}} & {\bf{Option(s)}} & {\bf{Argument(s)}} & {\bf{Description}} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{systemctl}} & \seqsplit{status} & sshd & Check the status of the SSH service. \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{systemctl}} & \seqsplit{restart} & sshd & Restarts the SSH service. \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} {\bf{journalctl}} & -u & ssh & See the log for SSH services, to look at problems. \tn % Row Count 10 (+ 3) % Row 4 \SetRowColor{LightBackground} {\bf{sudo ufw}} & & status & Looks at the rules set for the firewall. \tn % Row Count 13 (+ 3) % Row 5 \SetRowColor{white} {\bf{sudo cat}} & & \seqsplit{/etc/shadow/} & Looks at the shadow file. \tn % Row Count 15 (+ 2) % Row 6 \SetRowColor{LightBackground} | {\bf{grep}} & & {\emph{username}} & Pipes the search with grep to look for the username, if there is an exclamation mark at the beginning of the password field, that means the user is locked. \tn % Row Count 24 (+ 9) % Row 7 \SetRowColor{white} {\bf{sudo usermod}} & -U & {\emph{username}} & Unlocks the locked user account. \tn % Row Count 27 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}----} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Securing a SSH Server}} \tn % Row 0 \SetRowColor{LightBackground} 1) Don't allow the root user to log in & {\bf{PermitRootLogin}} no (or {\bf{prohibit-password}}) \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} 2) Prevent password logins, and allow keys & {\bf{PasswordAuthentication}} no\{\{nl\}\}{\bf{PubKeyAuthentication}} yes \tn % Row Count 7 (+ 4) % Row 2 \SetRowColor{LightBackground} 3) Change the service port & {\bf{Port}} {\emph{port number}} \tn % Row Count 9 (+ 2) % Row 3 \SetRowColor{white} 4) Change the encryption ciphers the server allows & {\bf{Ciphers}} ... (see {\bf{man}} sshd\_config) \tn % Row Count 12 (+ 3) % Row 4 \SetRowColor{LightBackground} 5) Enact user control & {\bf{AllowUser}}\{\{nl\}\}{\bf{DenyUser}}\{\{nl\}\}{\bf{AllowGroup}}\{\{nl\}\}{\bf{DenyGroup}} \tn % Row Count 16 (+ 4) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{6) Consider using software like Fail2ban to help prevent repeated malicious login attempts} \tn % Row Count 18 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{7) Consider designing your system to use a bastion host} \tn % Row Count 20 (+ 2) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{8) Consider putting your SSH server or bastion host behind a VPN} \tn % Row Count 22 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{1.584 cm} x{1.008 cm} x{1.512 cm} x{3.096 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{8.4cm}}{\bf\textcolor{white}{Tools That Use SSH (Mosh, Mobile Shell)}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{{\emph{Command}}}} & {\bf{Option(s)}} & {\bf{Argument(s)}} & {\bf{Description}} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{sudo apt install}} & & mosh & Install Mosh (needed in both the client and the server) \tn % Row Count 7 (+ 4) % Row 2 \SetRowColor{LightBackground} {\bf{sudo ufw}} & allow & \seqsplit{60001/udp} & Opens ports for Mosh (in the 60,000 range, only needed in the server). \tn % Row Count 12 (+ 5) % Row 3 \SetRowColor{white} {\bf{mosh}} & & {\emph{user}}@{\emph{ip address}} & Starts a Mosh session, just like a SSH connection. \tn % Row Count 15 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}----} \SetRowColor{LightBackground} \mymulticolumn{4}{x{8.4cm}}{Mosh provides a fault-tolerant shell experience. Mosh has to be configured in both the client and the server.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}----} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}