How to use Digital Ocean Spaces via command line

So you’re wondering, how can I use Digitial Ocean’s Spaces via command line to create new buckets in Spaces or to move data back and forth into a Space. You’ve come to the right place. In this how to, I will show you how to use command line and access your Spaces.

Keep in mind, we are doing this on a Fedora sever. You will need to change the installer to the one your system uses.

Install s3cmd:

dnf install s3cmd

Once you’ve installed s3cmd, you will need to configure it. Similar to how you would configure the AWS CLI.

s3cmd --configure

Before you can configure, you will need API credentials. See this post here on how to create API credentials for spaces.

Then fill in the configure with your API credentials.

Next you will set your region. US in our case.

Then end point. You can get your end point by going to your spaces bucket in your Digital Ocean dashboard. Hover over the endpoint link and it will show you your endpoints.

The endpoint is just url minus your bucket name. In this case it’s, nyc3.digitaloceanspaces.com

Next part is specifying your bucket endpoint. We did %(bucket)s.nyc3.digitaloceanspaces.com

You can then set an encryption key, which we highly recommend. You will then need to specify your GPG program path.

Decide on whether you should use HTTPs, it defaults to yes, seems pretty obvious to use it.

Then the proxy part is the last question. In our case it’s unneeded.

It should now be configured and you can create new buckets, put and remove files easily.

Let’s create a new Space/bucket:

s3cmd mb s3://mynewspace s3://myothernewspace

In this case, you can create 2 new spaces (mynewspace and myothernewspace)

Let’s move a file to our new space:

s3cmd put somefile.txt s3://mynewspace/

Let’s change the file name this time:

s3cmd put somefile.txt s3://mynewspace/newfilename.txt

How about multiple files? Let’s do it:

s3cmd put file1.txt file2.txt file3.text s3://mynewspace/

What if you want to get a file? Getting a file:

s3cmd get s3://mynewspace/file.txt

Deleting a space is up next:

s3cmd rb s3://myothernewspace

Deleting files from a space:

s3cmd rm s3://mynewspace/file.txt

Really simple stuff. s3cmd is awesome and makes managing Spaces on Digital Ocean a breeze!

For more information and s3cmd command usage, see this link: https://www.digitalocean.com/docs/spaces/resources/s3cmd-usage/

This post has referral codes to Digital Ocean. If you need hosting services, consider Digital Ocean. By clicking on this link, you’ll get a $100 credit for signing up today.

Leave a Reply