Set different user permissions for different directories
Background
-
If the UID of the same user on two virtual machines is the same, CFS will treat them as the same user; -
If the UIDs of the same user on two virtual machines are different, CFS will treat them as different users; -
If two different users have the same UID on different virtual machines, CFS will treat them as the same user.
Unified user UID and GID
-
If the user does not exist, create the user. Assume that the name of the user to be created is cfs, and check the UID and GID through the id command. The command and example output are as follows:
[ root@test-cfs ~ ] # useradd cfs
[ root@test-cfs ~ ] # id cfs
uid = five hundred ( cfs ) gid = five hundred ( cfs ) groups = five hundred ( cfs )
-
Use the usermode and groupmode commands to modify the UID and GID of the cfs account to a preset value, such as 888. The command and example output are as follows:
[ root@test-cfs ~ ] # usermod -u 888 cfs
[ root@test-cfs ~ ] # groupmod -g 888 cfs
[ root@test-cfs ~ ] # id cfs
uid = eight hundred and eighty-eight ( cfs ) gid = eight hundred and eighty-eight ( cfs ) groups = eight hundred and eighty-eight ( cfs )
Create initial directory
[ root@test-cfs ~ ] # mkdir /mnt/cfs
[ root@test-cfs ~ ] # chown -R cfs:cfs /mnt/cfs
[ root@test-cfs ~ ] # ls -l /mnt/ total eight drwxr-xr-x two cfs cfs four thousand and ninety-six Jul twenty-four fifteen :38 cfs drwxr-xr-x two root root four thousand and ninety-six Jul twenty-four fifteen :39 root
The kernel prohibits the use of non root users to mount the file system, so before users can use it, they still need to mount the file system with the root account. This step can be automated through "auto attach". When mounting at the same time, you can mount directly by the user's root directory path, limiting the use scope to users themselves.