Skip to content

Creating SSH keys

Create a secure SSH key pair in 5 minutes, so you can log into your own server without a password (and without the risk).

  • Beginner
  • 8 min
  • free
  • Draft · not tested yet

Before you rent a server, you first create your key. You’ll use it to log into your VPS: safer than a password and faster, because there’s nothing to type.

After this lesson you have: an SSH key pair on your computer, and you know which part you may share and which part never.

An SSH key consists of two files that belong together:

flowchart LR
  A["🔑 Private key<br/>id_ed25519<br/>(stays on your computer)"] -- proves who you are --> S[("🖥️ Server")]
  B["🔓 Public key<br/>id_ed25519.pub<br/>(fine to put anywhere)"] -- lives on --> S

Think of the public key as a lock you put on your server’s door, and the private key as the only key that fits that lock.

  1. Open a terminal.

    Open Terminal (Cmd + Space → type “Terminal”).
  2. Check whether you already have a key.

    Terminal window
    ls ~/.ssh

    See id_ed25519 and id_ed25519.pub? Then you already have one — skip to step 5. No passphrase on it yet? Add one with ssh-keygen -p (enter the path to your id_ed25519 when asked). Getting an error or an empty folder? Just carry on.

  3. Create the key pair. Replace the email address with yours (it’s just a label).

    Terminal window
    ssh-keygen -t ed25519 -C "you@example.com"

    When asked where to save the file, just press Enter (the default location is fine).

  4. Choose a passphrase. Don’t leave it empty: it protects your key if someone gets hold of your laptop (or the file). Nothing appears while you type — that’s expected.

    What you should see now

    Generating public/private ed25519 key pair.
    Enter file in which to save the key (/Users/you/.ssh/id_ed25519):
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in /Users/you/.ssh/id_ed25519
    Your public key has been saved in /Users/you/.ssh/id_ed25519.pub
    The key fingerprint is:
    SHA256:… you@example.com
  5. View your public key. You’ll copy this to your VPS provider later.

    Terminal window
    cat ~/.ssh/id_ed25519.pub

    What you should see now

    ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA… you@example.com

    One line, starting with ssh-ed25519. That’s what you share.

  6. Let your computer remember the passphrase (optional, saves typing).

    Terminal window
    ssh-add --apple-use-keychain ~/.ssh/id_ed25519

Checklist

0/4

Your progress is only stored in this browser.

Test yourself

  1. 1Which file may you give to your VPS provider?

  2. 2Why set a passphrase?

  3. 3Nothing appears while you type your passphrase. Now what?

Next lesson: renting a VPS from an EU provider and adding this key straight away.