Skip to content
Tutorials Center
My learning

Topics

Lesson 3 of 35 ยท Getting Started

Your First Droplet Step by Step: Create, Connect and Secure

Create a DigitalOcean Droplet, choose region, image and size, add an SSH key, connect, update Ubuntu, add a non-root user and enable the firewall. Includes the API payload.

A Droplet is the simplest way to get a server on DigitalOcean. In this lesson you will create one, connect with SSH, apply the basic hardening steps every new server needs, and see the same creation as an API request. Because the console is not available on this site, the steps are described precisely and the runnable code is a stand-in that builds and validates the request for you.

Step 1: choose the options

In the control panel you press Create and then Droplets. The form asks for these choices, in order:

  1. Region and VPC. Pick the region nearest your users, for example fra1. Leave the default VPC network unless you already designed one (see VPC private networking).
  2. Image. Choose an operating system. Ubuntu LTS releases are the most common and best documented. Marketplace images (WordPress, Docker, LAMP and others) come pre-installed.
  3. Size. Start small. A 1 vCPU, 1 GiB plan is enough for a personal site or a lab; see Droplet sizes and pricing.
  4. Authentication. Select an SSH key (strongly recommended) instead of a root password. The next-but-one lesson, SSH keys and access, explains how keys work.
  5. Options. Optional extras: backups, monitoring agent, IPv6, and user data for first-boot automation (cloud-init).
  6. Hostname, tags and project. Use a meaningful hostname such as web-1, add the tag web, and assign the Droplet to a project.

Press Create Droplet. After a short time the panel shows the public IPv4 address, for example 203.0.113.10 (a documentation-only address used here as an example).

Step 2: connect with SSH

From your terminal:

Terminal
ssh root@203.0.113.10

The first time, SSH asks you to confirm the server's fingerprint. Type yes. If you chose an SSH key and your private key is in the default location, you are logged in without a password.

Step 3: first-boot hardening

Running everything as root is risky, so do these five things right away:

Terminal
# 1. Update packages
apt update && apt upgrade -y

# 2. Create a normal user with sudo rights
adduser deploy
usermod -aG sudo deploy

# 3. Copy your SSH key to the new user
rsync --archive --chown=deploy:deploy ~/.ssh /home/deploy

# 4. Turn on the host firewall, allowing SSH first
ufw allow OpenSSH
ufw enable

# 5. Disable root login and password login for SSH
sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin no/' /etc/ssh/sshd_config
sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/' /etc/ssh/sshd_config
systemctl restart ssh

Open a second terminal and check that ssh [email protected] works before you close the first one. A mistake in the SSH settings can lock you out; the Droplet console in the control panel is the safety net.

You will later replace the host firewall (ufw) or complement it with a free Cloud Firewall that lives outside the Droplet; see Cloud Firewalls.

The same thing as an API request

Everything in the console is an API call. Creating a Droplet is a POST to https://api.digitalocean.com/v2/droplets with a bearer token and a JSON body:

JSON
{
  "name": "web-1",
  "region": "fra1",
  "size": "s-1vcpu-1gb",
  "image": "ubuntu-24-04-x64",
  "ssh_keys": ["3b:16:bf:e4:8b:00:8b:b8:59:8c:a9:d3:f0:19:45:fa"],
  "tags": ["web", "prod"],
  "monitoring": true,
  "ipv6": false
}

The key can be given as a numeric ID or as the key's fingerprint. The same request in doctl:

Terminal
doctl compute droplet create web-1 \
  --region fra1 --size s-1vcpu-1gb --image ubuntu-24-04-x64 \
  --ssh-keys 3b:16:bf:e4:8b:00:8b:b8:59:8c:a9:d3:f0:19:45:fa \
  --tag-names web,prod --enable-monitoring --wait

The next lesson covers doctl and the API in depth.

sequenceDiagram
  participant You
  participant API as DigitalOcean API
  participant Host as Hypervisor
  You->>API: POST /v2/droplets (JSON)
  API-->>You: 202 Accepted, droplet id, status "new"
  API->>Host: provision VM, attach disk, network
  Host-->>API: active
  You->>API: GET /v2/droplets/{id}
  API-->>You: status "active", public IPv4

Creation is asynchronous: the API accepts the request first, and the Droplet becomes active shortly afterwards.

A stand-in request validator

This program is not the real API. It builds a payload like the one above and checks the most common mistakes locally, so you can see what a good request looks like. The lists of regions, sizes and images are short samples, not the full catalog.

Python Stand-in: build and check a create-Droplet payload

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

After creation: what to look at

On the Droplet page you will find the Graphs (CPU, bandwidth, disk, with the monitoring agent), Networking (public and private addresses, firewalls, Reserved IP), Backups, Snapshots, Destroy, and a browser Console that works even if SSH is broken.

Remember: the Droplet is billed until you destroy it. If you were only practicing, delete it now (after you have finished reading the next lessons, perhaps) to avoid forgetting it.

Python Stand-in: a hardening checklist tracker

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which authentication method is recommended when creating a Droplet?

    SSH keys are far harder to guess or steal than passwords, and can be revoked per person.
  2. 2. What does the API return right after you POST a new Droplet?

    Creation is asynchronous. Poll the Droplet or use doctl's --wait flag.
  3. 3. Why test a second SSH session before closing the first after changing sshd settings?

    Keeping the working session open gives you a way to repair a broken configuration.
  4. 4. Which of these is NOT part of basic first-boot hardening?

    Fewer installed packages means a smaller attack surface.

Summary

  • Choose region, image, size, SSH key, options and tags, then create the Droplet; it becomes active asynchronously.
  • Connect as root once, then create a sudo user, update packages, enable a firewall and disable root and password SSH logins.
  • The console, doctl and the REST API are three views of the same operation.
  • Destroy practice Droplets, because idle ones are still billed.

Next: doctl and the DigitalOcean API