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:
{“sshkeys”:[{“id”:263654,“fingerprint”:“11:37:44:86:62:15:86:5f:0c:7d:41:0b:39:cb:3c:44”,“publickey”:“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.
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.
×
Still not working, but I think it should probably be closer to this (TOKEN is a valid token defined in my environment):
Output is:
This exact command but with “ssh_keys”:null works perfectly, creating a droplet.
Latest version, still failing:
And the output is:
I believe you want to use the fingerprint value (e.g. 11:37:44:86:62:15:86:5f:0c:7d:41:0b:39:cb:3c:44) not the actual public key.
So
I’m trying to add the key to the root user of the droplet I am creating. In fact I’m trying to add half a dozen fingerprints to each droplet for our team.
The goal is to avoid the onerous setup of having to log into each droplet and change the password from the one that was auto generated.
The answer below seems to be related to the digital ocean account ssh key. The keys I want to add are from my group’s public keys on off their laptops.
I feel confused. Which is which. Can you explain how I ssh into a droplet with my self generated key and how I format multiple keys into the root user with the api. Not all users who ssh into our droplets will have a digital ocean account.
From the V2 docs re: create new droplet:
ssh_keys - Array - An array containing the IDs or fingerprints of the SSH keys that you wish to embed in the Droplet’s root account upon creation.
Thanks,
Chris.