hennes' SSH cheatsheet

Copy public key to authorized keys on remote server

cat id_rsa.pub | ssh USER@SERVER 'cat>> ~/.ssh/authorized_keys'

or alternatively

ssh-copy-id -i ~/.ssh/id_rsa.pub USER@SERVER

Port forwarding

ssh -NfL LOCAL_PORT:TARGET_IP_ON_REMOTE_HOST:TARGET_PORT_ON_REMOTE_HOST USER@SERVER

No -f to keep ssh process in foreground.

Example

Forward port to remote MySQL at example.com on local port 3307:

ssh -NfL 3307:127.0.0.1:3306 bob@example.com

Show fingerprint

This is useful to check the key length of a key.

ssh-keygen -lf ~/.ssh/id_rsa.pub