Connect to servers, manage keys, copy files with scp and forward ports — the SSH commands worth knowing. Tap to copy.
ssh user@hostConnect to a remote machine over SSHssh -p 2222 user@hostConnect on a non-default portssh -i ~/.ssh/key.pem user@hostConnect using a specific private keyssh -v user@hostVerbose output for debugging connectionsssh-keygen -t ed25519 -C "you@example.com"Generate a new SSH key pairssh-copy-id user@hostInstall your public key on a serverssh-add ~/.ssh/id_ed25519Add a key to the ssh-agentcat ~/.ssh/id_ed25519.pubPrint your public key to copy itscp file.txt user@host:/path/Copy a local file to a remote serverscp user@host:/path/file.txt .Copy a remote file to your machinescp -r mydir user@host:/path/Copy a whole directory recursivelyscp -P 2222 file user@host:~Copy over a non-default port (capital P)ssh -L 8080:localhost:80 user@hostForward a local port to the remote sidessh -D 1080 user@hostCreate a local SOCKS proxyssh -N -f user@hostOpen a tunnel in the background, no shellnano ~/.ssh/configSave host aliases and options for reuseSSH connects you to remote machines securely. ssh user@host opens a shell; key-based login (with ssh-keygen and ssh-copy-id) is more secure and convenient than passwords. To move files, scp works just like cp but across machines. And SSH's tunnelling — ssh -L to forward a port — is a quietly powerful way to reach services running on a remote network as if they were local.