How to Access Files on DigitalOcean Spaces from Droplets via CLI
Object Storage like DigitalOcean Spaces are very powerful. However, being an external service also comes with its share of inconvenience.
What if I told you that we can interact with it like a local directory if we just mount it to our droplets? Here’s how.
If you are looking to transfer large amount of files between your Droplet and Spaces, check out this guide on using rclone instead. It’s much faster!
1. Install S3FS FUSE
The good thing about DigitalOcean Space is that it is S3-compatible. This enables a lot of S3 tools support out of the box. One fantastic tool we’ll use here is s3fs.
sudo apt-get update
sudo apt-get install s3fs
Once that is done, let’s setup your DigitalOcean Space credentials:
echo <space_key>:<space_token> > ~/.passwd-s3fs
chmod 600 ~/.passwd-s3fs
2. Managing 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(forge) gid=1000(forge) groups=1000(forge)…
In thise case, my user is forge
, so I’ve noted down the uid
and gid
of the user for the next step.
3. Mount DigitalOcean Space
First, make a mounting folder:
mkdir <folder>
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
Or if you want to mount a subfolder instead of the whole DO Space, you can do the following:
s3fs <space_name>:/<space_folder> <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
Now you should be able to do the usual stuff like cd
or ls
or cp
files etc like it’s inside the local harddisk. ❤
4. Unmounting
And if you ever need to unmount the Space, it’s also very easy:
fusermount -u <folder>
That’s all! Now you can manage your DigitalOcean Spaces just like a local directory.
Was it helpful?
If you find this article helpful, do give me a little clap on Medium. 😄 It really makes my day to know that I have helped a fellow developer out there. Thanks!