How to Mount a S3 Bucket on Linux Instance?

Step 1: Update the system.

If you are using a new Centos or Ubuntu instance, then update the system using the below commands:

a. For CentOS or Red Hat.

yum update all

b. For Ubuntu.

apt-get update

Step 2: Install the dependencies.

a. In CentOS or Red Hat.

sudo yum install automake fuse fuse-devel gcc-c++ git libcurl-devel libxml2-devel make openssl-devel

b. In Ubuntu or Debian.

sudo apt-get install automake autotools-dev fuse g++ git libcurl4-gnutls-dev libfuse-dev libssl-dev libxml2-dev make pkg-config

Step 3: Clone s3fs source code from git.

git clone https://github.com/s3fs-fuse/s3fs-fuse.git

Step 4: Install the code.

Now change to source code directory, compile and install the code with the following commands:

cd s3fs-fuse 
./autogen.sh
./configure --prefix=/usr --with-openssl
make
sudo make install

Step 5: Check the s3fs command and installation.

Use the below command to check where the s3fs command is placed in OS. It will also tell you the installation is ok.

which s3fs

Step 6: Paste the access key and secret key.

Create a new file in /etc with the name passwd-s3fs and paste the access key and secret key in the below format.

touch /etc/passwd-s3fs 
vim /etc/passwd-s3fs
Your_accesskey:Your_secretkey

Step 7: Change the permission of the file.

sudo chmod 640 /etc/passwd-s3fs

Step 8: Mount S3 bucket.

Now create a directory or provide the path of an existing directory and mount S3 bucket in it.

mkdir /mys3buckets3fs your_bucketname -o use_cache=/tmp -o allow_other -o uid=1001 -o mp_umask=002 -o multireq_max=5 /mys3bucket url=https://api-ap-south-mum-1.openstack.acecloudhosting.com:8080

You can make an entry in /etc/rc.local to automatically remount after reboot. Find the s3fs binary file by the which command and make the entry before the exit 0 line as below:

which s3fs 
/usr/local/bin/s3fs
nano /etc/rc.local 
/usr/local/bin/s3fs your_bucketname -o use_cache=/tmp -o allow_other -o uid=1001 -o mp_umask=002 -o multireq_max=5 /mys3bucket

Step 9: Check mounted s3 bucket.

df -Th

or

df -Th /mys3bucket

Last updated