如何实现Samba可读可写但不可删除?

Samba遇到一个需求,普通用户可以上传文件,可以修改文件,但是不能删除文件

到网上找了一些资料,好像都不行。

这个功能能实现吗?如何实现?

请大家不吝赐教!!!

:pray::pray::pray:

1赞

读了女王大人的回复,里面的一个链接非常有用:

https://ubuntuforums.org/showthread.php?t=1933466&p=11729534#post11729534

Edit: To cap this all off – If you create a file structure that has these 3 things:
a. A directory with the sticky bit set on.
b. The group forced (sgid)to one that is NOT a group with the samba users in it (i.e webadmin) and
c. The file permissions set read and write to the file, those users will be able to read and write to that file, but not delete the file.

所以我做了以下尝试:

一、设为共享文件夹

  1. 新建一个共享文件夹,假设是 /home/sss,文件夹的所有者为root
  2. 设定文件夹 /home/sss 的权限为 777
  # chmod 777 /home/sss
  1. 为文件夹 /home/sss 设置 sticky bit
  # chmod +t /home/sss

此时,/home/sss 的权限为

  drwxrwxrwt  5 root root 4096 3月  19 08:28 sss

二、设置samba配置

在 /etc/samba/smb.conf 中添加如下配置

[test_share]
  comment = This is a test!
  path = /home/sss
  writable = yes
  create mask = 1777
  directory mask = 1777
  inherit owner = yes
  force group = root
  1. writable = yes 允许上传文件
  2. create mask = 1777directory mask = 1777 允许文件可以修改
  3. inherit owner = yesforce group = root 修改上传的文件的属性,改变其所有者和所属组,使其与上传者的用户名和所属组不同,实现了不可删除

以上尝试基本实现了可读可写不可删除,但是空文件夹也不可删除,还需要继续研究。

1赞

为什么我自己搜索了半天也没找到靠谱的方案,而您发的链接却能解决问题。请问使用什么搜索引擎?或者有什么搜索技巧?请不吝赐教!

google 啊…关键词是 samba no delete permission。上不了 Google 没关系,手机下个短命 vpn 的 app,上一下 Google,搜“Google 反代”,有些人用自己博客的某个 URL 反代了 Google,直接访问那个地址就可以 Google,我不能泄漏但你自己能搜到

本主题在最后一个回复创建后60分钟后自动锁定。不再允许添加新回复。