By default, ossfs runs as the root user. To let a specific system user (such as www) own the mounted directory, mount the bucket as that non-root user. This topic walks through the full procedure on a Linux-based Elastic Compute Service (ECS) instance.
Prerequisites
Before you begin, make sure that you have:
An ECS instance running Linux
An OSS bucket
ossfs installed on the ECS instance. For more information, see Installation
The
/etc/passwd-ossfscredentials file created with valid AccessKey credentials in the format<bucket-name>:<access-key-id>:<access-key-secret>Root or sudo access for initial configuration
Procedure
This procedure uses www as an example non-root user. Replace www with your target user throughout.
Step 1: Create the non-root user
Skip this step if the user already exists.
useradd wwwStep 2: Get the UID and GID of the target user
Run the id command to get the UID and GID:
id wwwThe output is similar to:
uid=1001(www) gid=1001(www) groups=1001(www)Record the uid and gid values. You need them in the mount command.
Step 3: Configure credentials file permissions
Set the permissions to 640 and change the owner to the target user:
chmod 640 /etc/passwd-ossfs
chown -R www:root /etc/passwd-ossfsStep 4: Find the ossfs binary path
Run the following command to confirm the installation path:
which ossfsThe default path is /usr/local/bin/ossfs. Use the actual path returned if it differs.
Step 5: Create a mount directory
Switch to the target user and create a directory for the mount point:
su - www
mkdir ~/test1This example uses test1 as the directory name. Replace it with your preferred name.Step 6: Mount the bucket
Run the following command as the www user:
/usr/local/bin/ossfs <bucket-name> ~/test1 \
-ourl=<endpoint> \
-ouid=<uid> \
-ogid=<gid> \
-o passwd_file=/etc/passwd-ossfs \
-odefault_permission=750The following table describes each parameter:
| Parameter | Description | Example |
|---|---|---|
<bucket-name> | Name of the OSS bucket to mount | my-bucket |
<endpoint> | Endpoint of the region where the bucket is located | http://oss-ap-southeast-1.aliyuncs.com |
<uid> | UID of the target user, from Step 2 | 1001 |
<gid> | GID of the target user, from Step 2 | 1001 |
passwd_file | Absolute path to the credentials file | /etc/passwd-ossfs |
default_permission | Default permission mode for the mounted directory | 750 |
Step 7: Verify the mount
List the mount directory to confirm that the bucket is mounted and the ownership is correct:
ls -l ~/test1If the mount succeeds, the output shows the contents of your bucket with the www user as the owner.
Unmount the bucket
Use one of the following methods to unmount the bucket:
As the root user:
umount /home/www/test1As a non-root user:
fusermount -u /home/www/test1
Replace /home/www/test1 with the actual absolute path of your mount directory.