Adding SSH keys to a DigitalOcean account
There are two ways to log into a DigitalOcean droplet. If public key information is supplied during the creation of the droplet, then it will be added to the root user of the droplet. Otherwise, a one-time password is emailed to the registered user ID. Because of security implications, we strongly recommend using public keys and not passwords for logging in.
How to do it…
- For adding an SSH public key to our account, we will use the
digital_ocean_sshkey
module:
- name: Add SSH key to DO account digital_ocean_sshkey: name: "cookbook-key" ssh_pub_key: "{{ ssh_public_key }}" oauth_token: "{{ DO_OAUTH_TOKEN }}"
We have supplied a name along with the key. We need to add the token for the authentication as well.
- We will store the public key in the
roles/digitalocean/vars/main.yml
as a variable:
-- ssh_public_key: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCbg83WYIxUfXWJ4bQiYfZYHceDwMJxnGfJqgYtHL/DAtegVY+Nm8MX3CRZYisfskt0m9CQ6y/Ux1OITTz+O11fgxLJcroZmKJbWW0K39gfHvFqR7FIe0zuJaxqUQUuyc0i6RCBRiZPiQQOPes2yDtfHgDWx3q9knS3ZXIAXcGLZrgfC1XnIK8CLAnZDved9Rue2bhsCnO9Mleh9g...