Droplet user-data with new lines

Hi there,

is there a simple way to add a bigger user-data file into the string?

We have quite a few linebreaks and it is cumbersome to add those. Is there a recommended online tool to convert smth like


add-apt-repository -y ppa:ondrej/php
apt -y update
apt -y install nginx
apt -y install jq

into “#!/bin/bash \n add-apt-repository …”

The option to add a file link at whould be great too.




Submit an answer

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!

Sign In or Sign Up to Answer

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.

Hi there,

Yes, what you could do is to create a file and add that content into the file.

Let’s say that you’ve created a file called user-data.yml and you’ve added your script in there.

Then you could use the following curl request to spin up a new server with that user data file:

curl -X POST "" \
"'"$(cat ~/user-data.yml)"'",
      "ssh_keys":[ < SSH KEY IDs > ]}' \
      -H "Authorization: Bearer $TOKEN" \
      -H "Content-Type: application/json"

Hope that this helps!



Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up