Prerequisites
Before mounting an S3 bucket, make sure you have:
- SSH access to your VPS
- AWS access key and secret key
- S3 bucket name
Method 1: Using s3fs (Recommended)
Connect to your VPS:
ssh hxroot@YOUR_SERVER_IP -p 22
Install s3fs:
sudo apt update
sudo apt install s3fs -y
Create credentials file:
echo "ACCESS_KEY:SECRET_KEY" > ~/.passwd-s3fs
chmod 600 ~/.passwd-s3fs
Create mount point:
sudo mkdir -p /mnt/s3bucket
Mount bucket:
s3fs my-bucket-name /mnt/s3bucket -o passwd_file=~/.passwd-s3fs -o url=https://s3.amazonaws.com -o use_cache=/tmp
For other S3-compatible storage (e.g., DigitalOcean Spaces):
s3fs my-bucket /mnt/s3bucket -o passwd_file=~/.passwd-s3fs -o url=https://ams3.digitaloceanspaces.com -o use_path_request_style
Method 2: Using rclone (Alternative)
Install rclone:
curl https://rclone.org/install.sh | sudo bash
Configure S3:
rclone config
Choose s3 type, enter credentials, bucket region.
Mount:
mkdir ~/s3bucket
rclone mount s3:my-bucket ~/s3bucket --daemon
Method 3: Auto-mount at Boot (s3fs)
Add to /etc/fstab:
sudo nano /etc/fstab
my-bucket-name /mnt/s3bucket fuse.s3fs _netdev,allow_other,use_cache=/tmp,passwd_file=/home/user/.passwd-s3fs 0 0
Create Systemd Service for s3fs
sudo nano /etc/systemd/system/s3fs_mount.service
[Unit]
Description=S3FS Mount
After=network-online.target
[Service]
Type=forking
User=root
ExecStart=/usr/bin/s3fs my-bucket /mnt/s3bucket -o passwd_file=/root/.passwd-s3fs -o allow_other
ExecStop=/bin/fusermount -u /mnt/s3bucket
Restart=on-failure
[Install]
WantedBy=multi-user.target
Enable:
sudo systemctl daemon-reload
sudo systemctl enable s3fs_mount
sudo systemctl start s3fs_mount
Test Mount
df -h /mnt/s3bucket
echo "Hello S3" > /mnt/s3bucket/test.txt
Troubleshooting
If you see permission errors, add -o allow_other flag and ensure fuse.conf has user_allow_other:
sudo nano /etc/fuse.conf
# Uncomment: user_allow_other
Unmount:
sudo fusermount -u /mnt/s3bucket
✅ S3 bucket mounted. You can now read/write to cloud storage like a local directory.