ssh

Make a key pair with ssh-keygen, install it with ssh-copy-id, then log in to the server with ssh — no password.

>_ Try it: a simulated Linux, right here
Loading the terminal…

Examples

  • ssh-keygen -t ed25519
  • ssh-copy-id deploy@web-01
  • ssh deploy@web-01 hostname
  • ssh deploy@web-01
  • whoami
  • exit

How it works

ssh USER@HOST opens a shell on another machine: every command you type runs there, until exit brings you back.

Keys beat passwords: ssh-keygen makes a pair, a private key that never leaves your computer and a public key (.pub). ssh-copy-id puts the public one in the server's ~/.ssh/authorized_keys, and from then on the key logs you in.

Syntax

ssh [-i KEY] [-p PORT] USER@HOST [COMMAND]

Options

OptionWhat it does
USER@HOSTwho to log in as, and where
COMMANDrun one command there and come straight back
-i FILEuse this private key
-p PORTanother port than 22
ssh-keygenmake a key pair (-t ed25519)
ssh-copy-idinstall your public key on a server

Good to know

  • The private key must be readable by you only: ssh refuses it with "UNPROTECTED PRIVATE KEY FILE" otherwise (chmod 600).
  • The first time, ssh asks you to trust the server's fingerprint and remembers it in ~/.ssh/known_hosts.