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
-
If you don’t have a key yet, create one locally:
terminal ssh-keygen -t ed25519 -f ~/.ssh/origin-cloud -
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.
-
Verify that the key pair is listed:
terminal origin compute list-key-pairs --project-urn <project-urn>
Generate a key pair
-
Generate the key pair:
terminal origin compute generate-key-pair \ --project-urn <project-urn> \ --name my-keyThe response contains
privateKey, anssh-ed25519private key in OpenSSH format. -
Save
privateKeyto a file right away, and restrict its permissions. To do both in one go, generate the key pair and writeprivateKeystraight to a file withjq, 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 -
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:
mutation {
compute {
generateKeyPair(input: { projectUrn: "<project-urn>", name: "my-key" }) {
urn
publicKey
privateKey
}
}
}Next steps
- Launch an instance with the key pair