# sshLog in to a server
Syntax ssh [options] user@host
$ ssh deploy@203.0.113.10Copy
Log in as deploy
$ ssh -p 2222 deploy@example.comCopy
Use a different port
$ ssh -i ~/.ssh/id_ed25519 deploy@example.comCopy
Use a specific key
$ ssh deploy@example.com "df -h"Copy
Run one command and come back
$ ssh -J jump@bastion.example.com deploy@10.0.0.5Copy
Go through a jump host
Tip SSH Command does all of this with a Connect form. Type a Jump host in the dialog instead of using -J.
# ssh-keygenMake a key pair
Syntax ssh-keygen [options]
$ ssh-keygen -t ed25519 -C "me@example.com"Copy
Create a modern key (recommended)
$ ssh-keygen -lf ~/.ssh/id_ed25519.pubCopy
Show a key's fingerprint
$ ssh-keygen -R example.comCopy
Forget a server's saved fingerprint
# ssh-copy-idInstall your key on a server
Syntax ssh-copy-id user@host
# ssh-agent / ssh-addRemember key passphrases
Syntax ssh-add [key]
$ eval "$(ssh-agent -s)"Copy
Start the agent
$ ssh-add ~/.ssh/id_ed25519Copy
Unlock the key once per session
$ ssh-add -lCopy
List loaded keys
# scpCopy files over SSH
Syntax scp [options] source destination
$ scp report.pdf deploy@example.com:/home/deploy/Copy
Upload a file
$ scp deploy@example.com:/var/log/app.log .Copy
Download a file to the current folder
$ scp -r site/ deploy@example.com:/var/www/Copy
Copy a whole folder
$ scp -P 2222 file deploy@example.com:~Copy
A different port (capital P)
# sftpInteractive file transfer
Syntax sftp user@host
Tip Inside sftp, ls, cd and pwd work on the server; add an l (lls, lcd, lpwd) for your own computer.
# rsyncSmart copying and syncing
Syntax rsync [options] source destination
$ rsync -avz site/ deploy@example.com:/var/www/site/Copy
Upload only what changed, compressed
$ rsync -avz --progress deploy@example.com:/backups/ ./backups/Copy
Download with progress
$ rsync -avz --delete src/ dest/Copy
Make dest an exact mirror (deletes extra files)
$ rsync -avzn src/ dest/Copy
Dry run: show what would happen
Careful A trailing slash matters. src/ copies the contents of src; src copies the folder itself.
# ssh tunnelsForward ports
Syntax ssh -L / -R / -D
$ ssh -L 5432:127.0.0.1:5432 deploy@example.comCopy
Reach the server's database at localhost:5432
$ ssh -R 8080:localhost:3000 deploy@example.comCopy
Show your local site on the server
$ ssh -D 1080 deploy@example.comCopy
Make a SOCKS proxy at localhost:1080
# ~/.ssh/configShortcuts for servers
Syntax Host name
$ Host webCopy
A line in ~/.ssh/config
$ HostName 203.0.113.10Copy
Then add the address below it
$ User deployCopy
and the user; now just type: ssh web
# sshfsMount a remote folder
Syntax sshfs user@host:path mountpoint
$ mkdir -p ~/remoteCopy
Create an empty folder to use as the mount point
$ sshfs deploy@example.com:/var/www ~/remoteCopy
Work on server files as if local
$ fusermount -u ~/remoteCopy
Unmount