Can I use the Cloud API to add an SSH key to my account?

You can use the Cloud API to:

Add an existing SSH key to your account

To add an existing SSH key to your account:

  1. Generate an API key if you don’t have one already.

  2. Create a file named ssh-key.json that contains the necessary payload. For example:

    {
      "name": "my-new-key",
      "public_key": "ssh-ed25519 KEY COMMENT"
    }
    
  3. Run the following command:

    curl -u API-KEY: https://cloud.lambdalabs.com/api/v1/ssh-keys -d @ssh-key.json -H "Content-Type: application/json" | jq .
    

Replace API-KEY with your actual API key. Don’t remove the trailing colon (:).

Generate a new SSH key pair

To generate a new SSH key pair:

  1. Generate an API key if you don’t have one already.

  2. Run the following command:

    curl -u API-KEY: https://cloud.lambdalabs.com/api/v1/ssh-keys -d '{ "name": "my-generated-key" }' -H "Content-Type: application/json" | jq -r '.data.private_key' > my-generated-private-key.pem
    

    Replace API-KEY with your actual API key. Don’t remove the trailing colon (:).

  3. The private key for your SSH key pair will be saved as my-generated-private-key.pem.

    Run chmod 400 my-generated-private-key.pem to set the correct file permissions for your private key.

List the SSH keys saved in your account

To list the SSH keys saved in your account, generate an API key if you don’t already have one. Then, run the following command:

curl -u API-KEY: https://cloud.lambdalabs.com/api/v1/ssh-keys | jq .

Replace API-KEY with your actual API key. Don’t remove the trailing colon (:).

Delete an SSH key from your account

To delete an SSH key from your account, generate an API key if you don’t already have one. Then, run the following command:

curl -u API-KEY: -X DELETE https://cloud.lambdalabs.com/api/v1/ssh-keys/SSH-KEY-ID

Replace API-KEY with your actual API key. Don’t remove the trailing colon (:).

Replace SSH-KEY-ID with the ID of the SSH key you want to delete.