How to configure production Droplet on DigitalOcean
Create a DigitalOcean Droplet using the control panel or doctl CLI with Ubuntu 18.04 or later, SSH keys for authentication, enable IPv6, monitoring, backups, and VPC networking. Use a cloud-config user data script to set up a secure non-root user. Apply a cloud firewall with the Droplet's tag for inbound traffic control.
Prerequisites
- DigitalOcean account
- SSH key pair generated locally
- Basic command line knowledge
- Familiarity with cloud concepts
- Text editor for user data script
Step-by-Step Instructions
Generate and Upload SSH Keys
ssh-keygen -t ed25519 -C "your_email@example.com". Copy the public key content from ~/.ssh/id_ed25519.pub and upload it to your DigitalOcean account via the control panel under Security > SSH Keys > Add SSH Key.Start Droplet Creation in Control Panel
Choose Region and Image
Configure Networking and Features
Set Up User Data Cloud-Config Script
In the user data textbox, paste a cloud-config script customized with your desired non-root username (e.g., replace youruser):
cloud-config
users:
- name: youruser
sudo: ALL=(ALL) NOPASSWD:ALL
groups: sudo
shell: /bin/bash
ssh_authorized_keys:
- ssh-rsa AAAAB3NzaC1yc2E... your_key_here
lock_passwd: true
package_update: true
package_upgrade: true
packages:
- ufw
runcmd:
- ufw allow OpenSSH
- ufw --force enableThis creates a sudo user, adds your SSH key, disables password auth, and sets up basic firewall.
Configure Authentication and Tags
webserver for firewall rules. Set Quantity to 1 unless load balancing.Create the Droplet
s-2vcpu-2gb minimum for production), then click Create Droplet. Monitor the progress bar; the Droplet is ready when it shows an IP address (1-2 minutes).Alternative: Create with doctl CLI
doctl compute droplet create my-droplet --tag-names webserver --image ubuntu-22-04-x64 --region nyc3 --size s-2vcpu-2gb --ssh-keys your:key:fingerprint --user-data-file ./user-data.yaml --enable-ipv6 --enable-monitoring --enable-backupsReplace placeholders with your values.Create Cloud Firewall
webserver).Verify and Connect
ssh youruser@droplet-ip. Run ufw status and sudo systemctl status ssh to verify setup.Common Issues & Troubleshooting
SSH connection refused or timeout
Verify SSH key uploaded correctly and selected during creation. Check if firewall blocks port 22. Ensure you're connecting to public IP as non-root user created in user-data.
Droplet creation fails or stuck on progress bar
Check account credits/billing. Verify region/image availability. Try different region or basic plan size. Review API rate limits if using doctl.
'Permission denied' on SSH
Confirm public key matches private key used locally. Regenerate if fingerprint mismatch. Check user-data script properly added key to authorized_keys.
User data script not running
Validate YAML syntax (indentation critical). Use <code>doctl compute droplet-action power-off/on</code> to trigger cloud-init rerun. Check <code>/var/log/cloud-init-output.log</code> after SSH access.
Firewall blocks web traffic after setup
Edit cloud firewall rules to allow TCP 80/443 from 0.0.0.0/0. Verify Droplet tagged correctly and firewall applied. Test with <code>curl -I http://droplet-ip</code>.