How to Mount S3 Bucket on Ubuntu with s3fs-fuse

Mounting an Amazon S3 bucket to your local Ubuntu machine allows for smooth integration of cloud storage with your local filesystem. By using s3fs-fuse, you can interact with your S3 bucket as if it were a local directory, making file management tasks simple.

Benefits of using s3fs-fuse

  • Mount S3 buckets as local file systems.
  • Treat S3 buckets like regular directories.
  • Easily backup and retrieve data from S3 buckets.
How to Mount S3 Bucket on Ubuntu with s3fs-fuse

Prerequisites

  1. You need a registered AWS account to interact with Amazon services.
  2. Ensure that you have a private S3 bucket created in your AWS account where you wish to mount your local directory.
  3. Create an AWS IAM user with the necessary permissions to read and write to the specified S3 bucket.
  4. You should have access to an Ubuntu machine. It can be a local setup or a cloud-hosted instance.
  5. A basic understanding of Linux command line operations is required for setup and usage.

Step-by-Step Guide

Step 1: Installing s3fs-fuse

First, update your Ubuntu package list and install the s3fs-fuse package using the following commands:

sudo apt-get update
sudo apt-get install s3fs

Step 2: Configuring AWS Credentials

Create a .passwd-s3fs file in your home directory to store your AWS credentials securely:

echo ACCESS_KEY_ID:SECRET_ACCESS_KEY > ${HOME}/.passwd-s3fs
chmod 600 ${HOME}/.passwd-s3fs

Replace ACCESS_KEY_ID and SECRET_ACCESS_KEY with your actual AWS credentials.

How to Mount S3 Bucket on Ubuntu with s3fs-fuse

Step 3: Creating a Mount Point

Next, create a directory to serve as the mount point for your S3 bucket:

mkdir /path/to/local/mountpoint

Be sure to replace /path/to/local/mountpoint with the desired path for your mount point.

Step 4: Mounting the S3 Bucket

Now, mount your S3 bucket to the previously created mount point with s3fs:

s3fs mybucketname /path/to/local/mountpoint -o passwd_file=${HOME}/.passwd-s3fs

Here, mybucketname should be replaced with the name of your S3 bucket.

Example Output:

How to Mount S3 Bucket on Ubuntu with s3fs-fuse

Step 5: Test and Verify Mounting of Local Directory to S3 Bucket

Here’s how I tested this functionality:

I began by uploading an image file to the mounted S3 bucket directory. Then, I checked my S3 bucket directly to verify that the image file had indeed been uploaded, confirming the successful mounting of the local directory to the S3 bucket.

How to Mount S3 Bucket on Ubuntu with s3fs-fuse

Final Step: Ensuring Persistent Mounting

To keep the S3 bucket mounted after a reboot, add an entry to your /etc/fstab file:

echo 's3fs#mybucketname /path/to/local/mountpoint fuse _netdev,allow_other 0 0' | sudo tee -a /etc/fstab

Sample Output:

How to Mount S3 Bucket on Ubuntu with s3fs-fuse

Conclusion

With these steps, you’ve successfully mounted your S3 bucket to your local filesystem using s3fs-fuse. You can now begin transferring files between your Ubuntu machine and your S3 storage with ease. Remember to check the ownership and permission settings of the mount point to ensure proper access control.

We extend our heartfelt thanks to the dedicated community behind the s3fs package for Ubuntu. This invaluable tool has greatly simplified the process of mounting local folders to S3 buckets, making it accessible and user-friendly for countless users. We are truly grateful for their hard work and dedication. For more information about the s3fs package for Ubuntu, visit https://packages.ubuntu.com/focal/utils/s3fs.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.