How to mount s3 bucket as a local drive on CentOS ?

Here I’m going to set this up step by step…

We will use s3fs-fuse to integrate amazon s3 bucket into a CentOS Linux machine as a local drive.

Login to your server using PuTTy, login as root or get root permission via sudo command.

1. yum update

2. cd /tmp

3. yum -y install nano wget automake fuse fuse-devel gcc-c++ git libcurl-devel libxml2-devel make openssl-devel

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

5. cd s3fs-fuse

6. ./autogen.sh

7. ./configure

8. make

9. make install

After successful installation we need to get the Amazon S3 bucket details. We need the bucket name, bucket region, access key id, secret access key.

We have to obtain the URL to access the bucket, the URL can be created by knowing the bucket region. Suppose, if you created the bucket on “US East (N. Virginia) us-east-1” the URL will be https://s3-us-east-1.amazonaws.com or, if you created the bucket on “US West (Oregon) us-west-2” region then the URL will be https://s3-us-west-2.amazonaws.com

Once we have the bucket credentials ready we have to create a password text file in /etc directory.

10. cd /

11. nano /etc/passwd-s3fs

Write your bucket credential as accesskey:secretkey format in the password text file, then save and exit the file. (Note: Remember to give a colon <:> between the access key and secret key)
Example: AKIAQELQ4O63RP7EPXIU:q5ttpWDLbd1IyLHtKkhURgnLc3K5AgNcFW2JZBmZ

12. chmod 600 /etc/passwd-s3fs

I assume here that the local drive name is remotebackup and the s3 bucket name is relyfilestore and the bucket located in “US West (Oregon) us-west-2”
You should replace the bucket name, drive name and URL as yours.

13. mkdir /remotebackup

14. s3fs relyfilestore /remotebackup -o passwd_file=/etc/passwd-s3fs -o url=https://s3-us-west-2.amazonaws.com/ -o use_path_request_style -o dbglevel=info

15. nano /etc/fstab

Add the line of code listed below after the end line of the fstab file, replace the folder names and URL as yours, then save and exit the fstab file.

s3fs#relyfilestore /remotebackup fuse _netdev,allow_other,use_path_request_style,url=https://s3-us-west-2.amazonaws.com 0 0

16. reboot

Alldone !

After restarted the machine check the s3 drive as it in your local drive.

17. df -h

Enjoy unlimited storage !