DigitalOcean CLI Cheat Sheet


Add SSH key from local machine

keyFile=<Location of public key, ie. ~/.ssh/id_rsa.pub>
doctl compute ssh-key create "<NAME OF KEY>" --public-key "$(< $keyFile)"

Sane Webapp Firewall

Creates a firewall that has some workable/“sane” default rules for a webapp and assigns it to all droplets that have the tag default-webapp-fw.

Screenshots of the created firewall

Inbound:

Inbound rules

Outbound:

Inbound rules

doctl compute firewall create --name "default-webapp" --tag-names="default-webapp-fw" \
  --inbound-rules="protocol:icmp,address:0.0.0.0/0,address:::/0 protocol:tcp,ports:22,address:0.0.0.0/0,address:::/0 protocol:tcp,ports:80,address:0.0.0.0/0,address:::/0 protocol:tcp,ports:443,address:0.0.0.0/0,address:::/0" \
  --outbound-rules="protocol:icmp,address:0.0.0.0/0,address:::/0 protocol:tcp,ports:0,address:0.0.0.0/0,address:::/0 protocol:udp,ports:0,address:0.0.0.0/0,address:::/0"

See also