The first time I connect to a newly-created Droplet, I expect to be able to validate that the ECDSA key fingerprint is valid before adding it to my known_hosts file. I have not been able to find this information on the forum, how-to’s, or in the web console.
I’ve read through How To Connect To Your Droplet with SSH, and the DO moderator surprisingly recommends disregarding the possibility of a man-in-the-middle attack and blindly accepting the key. The actual statement is as follows: “The first time you attempt to connect to your server, you will likely see a warning that looks like this… The authenticity of host ‘123.123.123.123 (123.123.123.123)’ can’t be established… Go ahead and type yes to continue to connect. Here, your computer is telling you that the remote server is not recognized. Since this is your first time connecting, this is completely expected.” I agree that it’s expected. However, I don’t agree that that means it’s safe to assume that the connection is not compromised.
Back to my question then: Is there any way to validate the host’s fingerprint before connecting? Ideally it would be part of the response body when a new droplet is created or have its own API call.
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!
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.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
There are a number of methods you can use to verify the host keys on a Droplet. Each has some pros and cons.
The first way is to launch the web console while it is in the process of booting and view the output. This includes the key’s fingerprint. It looks like:
Unfortunately, that can be very hard to catch as it scrolls by.
The second option would be to log into the Droplet via the web console. This requires that you have a user with password authentication enabled. While you can disable this latter, I still consider this a major drawback. Once on the Droplet, you can check the fingerprint by running:
DigitalOcean has support for
cloud-init
which enables another set of options for verify the host keys.The first option utilizing
cloud-init
is generating a key locally and providing it via user data. One draw back to this approach is that the user-data is also served via the DigitalOcean metadata service. So any user on that specific Droplet could retrieve the key by runningcurl http://169.254.169.254/metadata/v1/user-data
Here’s an example:Next, you can use the “phone home” module provided by
cloud-init
. This is probably the cleanest solution, but it requires that you have a service listening for callbacks. It allows you to provide a URL which will receive a POST containing the Droplet’s public keys. You can limit it to only the ones you want, like so:Another draw back to the above approach is that you can not modify the format of the content. So if the service requires a specific format (e.g. Slack’s incoming webhooks), you’ll need a different approach. This is what I’ve used to post the fingerprint to Slack:
This fetches both the fingerprint and the Droplet’s ID and POSTs them to a Slack URL in the required JSON format.