How to Mount an Amazon S3 Bucket Locally Using s3fs on Ubuntu

Amazon S3 (Simple Storage Service) is one of the most reliable and widely used cloud storage solutions available. However, interacting with S3 typically requires using the AWS Management Console, the AWS CLI, or an SDK. What if you could interact with an S3 bucket exactly as if it were a folder on your local Linux machine?

Thanks to s3fs-fuse (S3 File System based on FUSE), you can. This utility allows you to mount an Amazon S3 bucket as a local file system directory in Ubuntu, enabling you to read, write, and manage cloud files using standard Linux commands (like cp, mv, and rm) or even graphical file managers.

Prerequisites

Before proceeding, ensure you have the following:

  • A machine running Ubuntu Linux (these instructions also apply to Debian-based derivatives).
  • An active AWS Account with an existing S3 bucket.
  • An IAM user with programmatic access (Access Key ID and Secret Access Key) and read/write permissions for the target S3 bucket.

Step 1: Install s3fs

The s3fs package is available in the default Ubuntu repositories, making installation incredibly simple. Open your terminal and run:

sudo apt update
sudo apt install s3fs

Step 2: Configure Your AWS Credentials

In order for s3fs to connect to your AWS account, it needs your IAM credentials. You must store these credentials in a specific hidden file (.passwd-s3fs) within your home directory.

Use the following command, replacing YOUR_ACCESS_KEY and YOUR_SECRET_KEY with your actual IAM credentials:

echo YOUR_ACCESS_KEY:YOUR_SECRET_KEY > ~/.passwd-s3fs

For security reasons, s3fs requires that this credential file is strictly protected. If the permissions are too loose, s3fs will refuse to mount the bucket. Restrict the permissions so that only the owner can read it:

chmod 600 ~/.passwd-s3fs

Step 3: Create a Local Mount Point

Next, you need an empty directory on your Ubuntu machine where the S3 bucket will be mounted. Let’s create a directory named s3-drive inside the user’s home folder:

mkdir ~/s3-drive

Step 4: Mount the S3 Bucket

Now you are ready to mount the bucket. Use the s3fs command followed by your bucket name and the path to your mount directory. If your bucket is named my-company-backup-bucket, the command will look like this:

s3fs my-company-backup-bucket ~/s3-drive -o passwd_file=~/.passwd-s3fs

Once you press Enter, there won’t be any output if it is successful. You can verify the mount by running the df -h command. You should see your S3 bucket listed as a file system.

Step 5: How to Unmount the Bucket

When you are finished working with your cloud files, you should safely unmount the directory to ensure all background transfers complete. Use the standard Linux umount command:

sudo umount ~/s3-drive

Limitations to Keep in Mind

While s3fs is a fantastic productivity tool, it is important to understand its limitations. S3 is an object storage service, not a block storage volume like a standard hard drive or an EBS volume. Because of this:

  • Latency: Editing a large file directly inside the mounted directory can be slow, as the entire file must often be downloaded, modified, and re-uploaded in the background.
  • Database Hosting: Never host active databases (like MySQL or PostgreSQL) on an s3fs-mounted directory. The latency and lack of block-level locks will quickly corrupt your database.

Conclusion

Mounting an Amazon S3 bucket locally using s3fs provides an incredibly intuitive way to manage cloud storage. It bridges the gap between local Linux workflows and scalable AWS cloud architecture, allowing you to drag, drop, and manage files without ever leaving your terminal or graphical file manager.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.

Receive our best articles and tips delivered straight to your inbox.