In this article, we will be using S3FS to mount cloud storage services locally on a CentOS or Ubuntu box. Mounting them locally will allow us to interact with the cloud providers as a local file system.

We will be covering three cloud storage providers namely, AWS S3, Wasabi Hot Storage and Digital Ocean Spaces. What makes this interesting is that all three providers use the same api, which is the S3 API.

S3FS is a FUSE (File System in User Space) based solution used to mount an Amazon S3 or compatible storage solutions, Just as mentioned above, we can use system commands with this drive just like as another Hard Disk in the system. On s3fs mounted files systems we can simply use cp, mv and ls the basic Unix commands similar to run on locally attached disks.

Step 1 – Update Packages

First, we will update the system to make sure we have the latest packages. We will then check if we have any existing s3fs or fuse package installed on your system. We will remove any existing packages and install everything anew.

### CentOS and RedHat Systems ###
$ yum update
$ yum remove fuse fuse-s3fs

### Ubuntu Systems ### 
$ sudo apt-get update
$ sudo apt-get remove fuse

Step 2 – Install Dependencies

Once you have successfully removed the packages. We will install all dependencies for fuse. Install the required packages to system use following command.

### CentOS and RedHat Systems ###
yum install gcc libstdc++-devel gcc-c++ curl-devel libxml2-devel openssl-devel mailcap

### Ubuntu Systems ### 
sudo apt-get install build-essential libcurl4-openssl-dev libxml2-dev mime-support

Step 3 – Download and Compile Latest S3FS

In this step we will download and compile the latest version of s3fs from GitHub. For this article we are using s3fs version 1.74. After downloading extract the archive and compile source code in system using the commands below.

Debian 9 and Ubuntu 16.04 or newer:

sudo apt install s3fs


RHEL and CentOS 7 or newer through via EPEL:

sudo yum install epel-release
sudo yum install s3fs-fuse


Step 4 – Configuring Access Key

In order to configure s3fs, we would require Access Key and Secret Key of your S3 Amazon account, Wasabi or Digital Ocean. You can access these keys from you account dashboard of the respective services. Once you have these keys, create a file, for the purpose of this tutorial we will be naming the file pwd-s3fs.

### Note: Change AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY with your actual key values.

After creating the password file we will change the permission on the file for security reasons.

chmod 600 ${HOME}/.passwd-s3fs

Step 5 – Mount S3 Bucket

Finally we can mount the s3 bucket using following set of commands. For this example, we are using s3 bucket name as test-bucket and mount point as /s3mnt.

mkdir /tmp/cache /s3mnt
chmod 777 /tmp/cache /s3mnt
s3fs -o use_cache=/tmp/cache mybucket /s3mnt -o passwd_file=${HOME}/.passwd-s3fs

Once this has been successfully run, you will be able to access all files within the test-bucket by just changing directories into /s3mnt.

Step 6 – Mounting a Wasabi Hot Storage Bucket

If you are not familiar with Wasabi, It’s a S3 compatible storage which is 1/5th the price and 6x faster than Amazon S3, according to their website. Since it supports the S3 API the same command works, you only need to change the endpoint as describe below:

s3fs test-bucket /s3mnt -o passwd_file=/etc/pwd-s3fs -o url= 

Step 7 – Mounting a Digital Space

Just like the approach with Wasabi we will be specifying the endpoint in the command. Use the command below to mount a digital ocean space unto your local drive.

s3fs test-bucket /s3mnt -o passwd_file=/etc/pwd-s3fs -o

How to unmount

In order to unmount the folders , just do the next: 

umount -l /tmp/cache
umount -l /s3mnt


If you are using S3FS for web app, you will need to allow apache or www-data or … (user runs web server) access mounted S3. Add option allow_other to archive this, so the command will be

s3fs -o allow_other,use_cache=/tmp/cache mybucket /s3mnt

In most cases, you will want S3 to be mounted automatically after each reboot. So, add below line to /etc/fstab. Please note that fstab is run by root user, so you need to copy .passwd-s3fs to root home directory if it was not there (or you can use /etc/passwd-s3fs for system-wide configuration)

s3fs#mybucket /s3mnt fuse allow_other,use_cache=/tmp/cache 0 0

If you have more than 1 bucket to mount to same system, you will need to use startup script instead of fstab because if you use fstab, only 1 bucket will be mounted. With Ubuntu, using local.rc may be the best choice for startup script


In Conclusion

In this article we have reviewed how to use s3fs to mount cloud storage services locally. By doing so we can use regular linux commands to interact with the files within the remote bucket locally. Some use cases include running backups, copying files and a whole lot more.