对于某个待共享的文件夹 /ftp/Shared
可以按照以下方法设置多个用户访问
此方法同时适用于ftp、samba、qB等需多用户访问读写的文件夹情况
添加新共享专用用户组 sudo groupadd ftp
设置待共享文件夹用户组为此用户组 sudo chown :ftp /ftp/Shared
添加用户到此用户组 sudo usermod -a -G ftp jeremie
,此处进行多次,将所有需共享的用户都添加到此用户组中
【注意:用户的用户组更新后,如果当前用户已经处在登陆状态,则需要退出并重新登陆,用户的用户组信息才会更新[1]】
设置待共享文件夹的属性为 sudo chmod 2770 /ftp/Shared
在此处参数有以下释义[2]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| Now you have some decisions to make about what you want those users to be able to do:
[a] All group users can add to and delete from the folder and can read and but not write to each others files:
sudo chmod 0770 /ftp/Shared
[b] Same as above but only the owner of the file can delete it:
sudo chmod 1770 /ftp/Shared
[c] All group users can add to and delete from the folder and can read and write to each other's files:
sudo chmod 2770 /ftp/Shared
[d] Same as [c] except only the owner of the file can delete it:
sudo chmod 3770 /ftp/Shared
A 1 in the first position of the chmod command is the sticky bit which prevents deletion of a file to anyone other than the owner.
A 2 in the first position of the chmod command is the setgid bit which forces all new or copied files to have the group of that folder.
A 3 in the first position of the chmod command is the combination of the sticky (1) & setgid (+2) bits.
|
参见:
[1]: https://askubuntu.com/questions/313089/how-can-i-share-a-directory-with-an-another-user
[2]: https://wiki.archlinux.org/title/users_and_groups