Chapter 10: Secure remote access

SSH cheat sheet

The chapter on one page: what to remember, the commands to have at your fingertips, and flashcards for quick revision.

The chapter in eight sentences

Cheat sheet

Client

CommandDoes
ssh user@host [cmd]Log in / run a command
ssh -i KEY user@hostUse a given private key
ssh-keygen -lF HOSTFingerprint stored in known_hosts
ssh-keygen -lf FILE.pubFingerprint of a key file
ssh-keygen -R HOSTForget a host key
-o StrictHostKeyChecking=accept-newAccept new hosts, refuse changed ones

Keys

CommandDoes
ssh-keygen -t ed25519 -f ~/.ssh/NAME -C TEXTNew key pair
ssh-keygen -p -f KEYChange the passphrase
ssh-copy-id -i KEY.pub user@hostInstall the public key
eval $(ssh-agent -s), ssh-add KEY, ssh-add -lAgent
~/.ssh 700 · authorized_keys 600Required permissions
journalctl -u sshdWhy a login failed

Transfer and server

CommandDoes
scp F host: · scp -r D host:/path/ · scp host:F .Copy once
sftp hostInteractive transfer
rsync -av D/ host:D/Synchronise
rsync -avn --delete D/ host:D/Dry run of a mirror
/etc/ssh/sshd_config.d/10-NAME.confYour sshd settings
sshd -t · sshd -T | grep optCheck syntax · effective values
systemctl reload sshdApply without dropping sessions

Flashcards

Log in and run a command remotely?
ssh user@host · ssh user@host command
What is in known_hosts, and what does a warning mean?
The host keys you trust. A changed key means a rebuilt server or an attack: find out which.
Create a key pair and install the public key?
ssh-keygen -t ed25519 · ssh-copy-id -i KEY.pub user@host
Which key file is secret?
The private key (no .pub). Mode 600.
Permissions sshd insists on?
~/.ssh 700, authorized_keys 600, both owned by the user.
Load a key once for many logins?
eval $(ssh-agent -s) · ssh-add KEY
Copy a file, a directory, and synchronise?
scp F host: · scp -r D host: · rsync -av D/ host:D/
A short name for a server?
Host block in ~/.ssh/config: HostName, User, IdentityFile
Where do sshd changes go, and in what order are they read?
/etc/ssh/sshd_config.d/*.conf, alphabetical, first value wins: name yours 10-...
Check and apply sshd configuration?
sshd -t · sshd -T | grep OPTION · systemctl reload sshd
Remove a stale host key?
ssh-keygen -R HOST
Where are SSH logins logged?
journalctl -u sshd and /var/log/secure