This quick reference cheat sheet provides various for using SSH.

#Getting started


Connect to a server (default port 22)

$ ssh [email protected]

Connect on a specific port

$ ssh [email protected] -p 6222

Connect via pem file (0600 permissions)

$ ssh -i /path/file.pem [email protected]


Executes remote command

$ ssh [email protected] 'ls -l'

Invoke a local script

$ ssh [email protected] bash < script.sh

Compresses and downloads from a server

$ ssh [email protected] "tar cvzf - ~/source" > output.tgz


Copies from remote to local

$ scp [email protected]:/dir/file.ext dest/

Copies between two servers

$ scp [email protected]:/file [email protected]:/dir

Copies from local to remote

$ scp dest/file.ext [email protected]:/dir

Copies a whole folder

$ scp -r [email protected]:/dir dest/

Copies all files from a folder

$ scp [email protected]:/dir/* dest/

Copies from a server folder to the current folder

$ scp [email protected]:/dir/* .

#Config location

System-wide ssh config


User-specific ssh config


#SCP Options

Options Description
scp -C Compresses data
scp -v Prints verbose info
scp -P 8080 Uses a specific Port

#Config sample

Host server1 
    User root
    Port 22
    IdentityFile ~/.ssh/server1.key

Launch by alias

$ ssh server1

See: Full Config Options


$ ssh -J proxy_host1 remote_host2
$ ssh -J [email protected]_host1 [email protected]_host2

Multiple jumps

$ ssh -J [email protected]_host1:port1,[email protected]_host2:port2 [email protected]_host3


$ ssh-copy-id [email protected]

Copy to alias server

$ ssh-copy-id server1

Copy specific key

$ ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]

#SSH keygen


$ ssh-keygen -t rsa -b 4096 -C "[email protected]" 

- - -
-t Type of key
-b The number of bits in the key
-C Provides a new comment

Generate an RSA 4096 bit key with email as a comment


Generate a key interactively

$ ssh-keygen

Specify filename

$ ssh-keygen -f ~/.ssh/filename

Generate public key from private key

$ ssh-keygen -y -f private.key > public.pub

Change comment

$ ssh-keygen -c -f ~/.ssh/id_rsa

Change private key passphrase

$ ssh-keygen -p -f ~/.ssh/id_rsa

#Key type

  • rsa
  • ed25519
  • dsa
  • ecdsa


Search from known_hosts

$ ssh-keygen -F <ip/hostname>

Remove from known_hosts

$ ssh-keygen -R <ip/hostname>

#Key format

  • PEM
  • PKCS8

#See also