Question

API: Adding SSH key when creating a droplet

When creating a droplet via the API, you can pass in an SSH key.

What is the format of the key? I am guessing it would be like this, based on return value of the List All Keys API:

{“ssh_keys”:[{“id”:263654,“fingerprint”:“11:37:44:86:62:15:86:5f:0c:7d:41:0b:39:cb:3c:44”,“public_key”:“ssh-rsa ZZZB3NzaC1yc2EAAAADAQABAAABAQC6vHxLRqVEN2Ze9f8ii634wP5f0Ysua+zqcedJFy8D6/biGE2b0pr0fZoB0lyypu3d6uxt8DvxNNRSgcDiZ6JUoTqPWVY252xgaykghBuNsTSFboAT+c/J9/8GQnTJx5PbiUAMeOBsQ6bU3rkhidhsxDyUzp8PyvTHZxopuCZ/QD/qTRgnpXLiV5/RiKMfg69dRLpG9nTWAfXKb4cwBQesPvfSzPemyMWorkLRbnGlDH3s81yIRNDTO9/LKMIPov715lXF4njbvazSnqjLMLNW4MTvSpUt6LFBv4gKCHgqK0V68QV4Py6BDWhpI0nyzZRlnAxKThbJ3nGDThc4d8m5x tom@tomsmacbook.local”,“name”:“For tomsmacbook”}],“links”:{},“meta”:{“total”:1}}

I am still a little fuzzy about SSH and so am not sure exactly what SSH key to pass in. I am guessing I want it to be the public key file (named id_rsa.pub by default) that was created at the same time as the private key my machine uses?

Thanks much.

P.S. Key contents, machine IDs, etc. were changed to protect the innocent.

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

hi, instead of the actual key you have to send the ID of the key.

  1. generate the key (which it looks like you’ve already done)
  2. add your public key via https://cloud.digitalocean.com/ssh_keys or API https://developers.digitalocean.com/documentation/v2/#create-a-new-key
  3. get the ID of the added public key via API call curl -X GET -H ‘Content-Type: application/json’ -H ‘Authorization: Bearer $TOKEN’ “https://api.digitalocean.com/v2/account/keys
  4. use this ID for you droplet creation call: …,“ssh_keys”:[123456]… enjoy!

This works for me:

curl -X GET "https://api.digitalocean.com/v2/account/keys" -H "Authorization: Bearer $DO_API_TOKEN"

It works for me when use the following;

curl -X POST “https://api.digitalocean.com/v2/droplets” -d’{“name”:“server1.example.com”,“region”:“nyc3”,“size”:“512mb”,“image”:“centos-6-5-x64”,“ssh_keys”:[“95:0d:c5:a9::xxxx:xxxx:f7:fa”]}’ -H “Authorization: Bearer $TOKEN” -H “Content-Type: application/json”

$TOKEN is my API key