After creating a Dokku One-Click Droplet, you need to visit the Droplet’s IP address in a browser to finish configuring Dokku. If you don’t, the Dokku instance will be vulnerable to anyone who finds the setup page and inserts their key.
When you visit the setup page, you’ll see three fields:
- Public Key
- Use virtualhost naming for apps:
Since this topic is about the Public key, we’ll only be talking about that one but if anyone wants to learn more about dokku and the other configuration during setup they can do it here Dokku Quickstart
Now, onto the Public key! During the setup process, If you uploaded an SSH key to the Droplet when you created it, this field will be pre-populated with your public key. If not, add an SSH public key here.
Please note that you need to add your Public key file here! Usually, that’s the file id_rsa.pub.
Having said that if by any reason you can’ push to git afterwards and you want to change/add/remove an SSH key, there is a pretty easy way to do so from your Droplet.
SSH to your droplet
You have 3 commands which can help you manage your keys:
ssh-keys:add <name> [/path/to/key]
ssh-keys:list [--format text|json] [<name>]
ssh-keys:remove [--fingerprint fingerprint|<name>]
I’ll go over the 3 commands where I’ll just mention the list and remove command and give more information on the add command as this is what we are after now.
You can use the ssh-keys:list command to show all configured SSH keys. Any key added via the dokku-installer will be associated with the admin key name.
As key names are unique, they can be used to remove a public SSH key.
dokku ssh-keys:remove KEY_NAME
An SSH Key can also be removed by fingerprint.
dokku ssh-keys:remove --fingerprint FINGERPRINT
Both KEY_NAME and FINGERPRINT can be found using the dokku list command.
Now, onto what we are after! You can add your public key to Dokku with the ssh-keys:add command. The output will be the fingerprint of the SSH key.
dokku ssh-keys:add KEY_NAME path/to/id_rsa.pub
KEY_NAME is the name you want to use to refer to this particular key. Including the word admin in the name will grant the user privileges to add additional keys remotely.
Alternative way to add your SSH key and the one I use is running the below command on your local enviroment(laptop) the following command:
cat ~/.ssh/id_rsa.pub | ssh email@example.com dokku ssh-keys:add KEY_NAME