Skip to content

Compute / Task

Create a key pair

Updated · 2 min read

Import the public half of an SSH key you already have, or have the platform generate a key pair and save its private key from the one response that carries it.

On this page6 sections

Create a key pair before you launch an instance. Import a key you already have, or have the platform generate one. Importing is the safer default, because the private key never leaves your computer.

Before you begin

Import an existing key

  1. If you don’t have a key yet, create one locally:

    terminal
    ssh-keygen -t ed25519 -f ~/.ssh/origin-cloud
  2. Import its public half. Pass the full OpenSSH public key line:

    terminal
    origin compute import-key-pair \
      --project-urn <project-urn> \
      --name my-key \
      --public-key "$(cat ~/.ssh/origin-cloud.pub)"

    A key with an unsupported type, or more than one line, is refused.

  3. Verify that the key pair is listed:

    terminal
    origin compute list-key-pairs --project-urn <project-urn>

Generate a key pair

  1. Generate the key pair:

    terminal
    origin compute generate-key-pair \
      --project-urn <project-urn> \
      --name my-key

    The response contains privateKey, an ssh-ed25519 private key in OpenSSH format.

  2. Save privateKey to a file right away, and restrict its permissions. To do both in one go, generate the key pair and write privateKey straight to a file with jq, instead of running the command above on its own:

    terminal
    origin compute generate-key-pair \
      --project-urn <project-urn> \
      --name my-key \
      | jq -r '.. | .privateKey? // empty' > ~/.ssh/origin-cloud
    chmod 600 ~/.ssh/origin-cloud
  3. Verify that the key pair is listed:

    terminal
    origin compute list-key-pairs --project-urn <project-urn>

Using the API

The importKeyPair and generateKeyPair mutations take the same inputs. Request privateKey in the generateKeyPair selection, or you can’t get it later:

GraphQL
mutation {
  compute {
    generateKeyPair(input: { projectUrn: "<project-urn>", name: "my-key" }) {
      urn
      publicKey
      privateKey
    }
  }
}

Next steps