I’m trying to create droplets with SSH key using the python-digitalocean library. For some reasons the ssh key is not attached to the newly created droplet.
Any idea what can I do ?| Thanks !
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.
Click below to sign up and get $100 of credit to try our products over 60 days!
Did something change to the API or … ?
I’ve already tried the second approach presented and doesn’t work.
Then:
Result:
Droplet IP: AA.BB.CC.DD, SSH KEYS: [] …
I do have a key on DO:
python-digitalocean accepts SSH keys in multiple formats when creating a new Droplet. One important thing to remember is that even if you are only adding one key, the attribute needs to be in list form.
Here’s a quick example:
This example highlights the three forms that are accepted:
keys[0]
is an SSHKey object that was retrieved usingclient.get_all_sshkeys()
3939600
is the ID of an SSH key on my DigitalOcean account as an integerb6:2e:fa:ea:96:42:14:1b:62:e2:76:4b:6f:60:1a:e6
is the fingerprint of an SSH key on my DigitalOcean accountIf you’d like to add all of the keys on you account to a Droplet, the easiest way would be:
This works since
client.get_all_sshkeys()
already returns them in a list.