Question

How to mount DigitalOcean Spaces on droplets with s3fs

I’ve recently got asked how to mount a space on a droplet and I would like to create a separate question here in the community where everyone can share their ideas and valuable information.

Show comments

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.

Accepted Answer

Hello, @TsungyingChen

You can mount a DigitalOcean space on your droplet and use it for storage of some of you data. In general, object storage solutions like Spaces are not meant to be accessed like a file system. They are API driven and most often used programmatically. You can check out this tutorial to learn more about object storage and if it’s right for your use case:

https://www.digitalocean.com/community/tutorials/object-storage-vs-block-storage-services#what-is-object-storage

I’ve recently posted a question in the community on how to manage DigitalOcean Spaces using s3cmd:

https://www.digitalocean.com/community/questions/how-to-manage-digitalocean-spaces-using-s3cmd

You can use s3cmd in order to mount the Space to your droplet and from there you can transfer files directly to your Spaces. s3cmd also have a feature to sync directories. In this way you can always make sure that you have all of your latest project files uploaded to your bucket:

You can also use other tools like s3fs in order to mount the space. Also you can mount the Space on multiple droplets, there is no issue in doing that.

You need to do few steps:

1 First is to install s3fs:

sudo apt-get update sudo apt-get install s3fs

2 Once that is done you need to setup your DigitalOcean Space credentials:

echo <space_key>:<space_token> > ~/.passwd-s3fs
chmod 600 ~/.passwd-s3fs

3 You need to sort the user permissions:

By default, DigitalOcean Space is mounted for root user. Because of that, any files or folders that are created via the web control panel is not accessible by non-root users after it’s mounted, which is not ideal. To make sure that we can access it via a non-root user, we need to update the config file:

sudo nano /etc/fuse.conf

Uncomment the part that says:

user_allow_other

Next, find out your user’s details by typing the following command:

id

You’ll see an output like this:

uid=1000(sammy) gid=1000(sammy) groups=1000(forge)…

In this case, the user is sammy, so you need to note down the uid and gid of the user for the next step.

4 Mount DigitalOcean Space

First, make a mounting folder:

mkdir <folder>

e.g replace the <folder> with the actual folder you would like to use, the command will be: mkdir space-storage

Then, let’s mount the Space to our new folder:

s3fs <space_name> <folder> -o url=https://sgp1.digitaloceanspaces.com -o use_cache=/tmp -o allow_other -o use_path_request_style -o uid=1000 -o gid=1000

Note: replace the space_name , folder and the uid , gid with your actual space name, created folder and the user IDs received from the id command in step 3

If you want to unmount the space you need to execute this command:

fusermount -u <folder>

That’s all for using s3fs with DigitalOcean’s Spaces.

Thanks to Jian Jye for sharing this article originally on

https://jianjye.medium.com/how-to-mount-digitalocean-spaces-to-droplets-on-ubuntu-dcba4cc16c78

Hope this helps! Regards, Alex

The accepted answer here helped me a lot, but if you want to store files with public read permissions, there’s a little more:

Firstly I found the ACL had to be set with another option of default_acl=public-read e.g:

s3fs <space_name> <folder> -o url=https://<region>.digitaloceanspaces.com -o use_cache=/tmp -o allow_other -o use_path_request_style -o uid=<uid> -o gid=<gid> -o default_acl=public-read

And if you’re mounting this with fsab then this in /etc/fstab seems to work after reboots:

<bucket> <folder> fuse.s3fs _netdev,allow_other,uid=<uid>,gid=<gid>,default_acl=public-read,use_path_request_style,url=https://<region>.digitaloceanspaces.com/ 0 0

I’m not very familiar with fstab and mounting things. I’m not sure if a cache option should be in there, and I’ve not yet looked up all the options.

The examples here helped too: https://github.com/s3fs-fuse/s3fs-fuse , especially for the stab format and handling of the /etc/passwd-s3fs file.

Hello @massimilianomoraca

Thanks for sharing this information. I also believe other users can find it useful if they run into the same situation.

Regards, Alex

Hello, @massimilianomoraca

That is really weird. Would you mind trying to replicate this using an alternative browser and if the issue persists you can also try reaching out to our support team?

Regards, Alex