大网数据广告活动
服务器运维问答

how can I allow my user to copy files onto samba share without root (sudo)?

· 52CE 我爱测

I mounted a samba share on my system to a mount point I made accessible to the world with chmod 777 and chown -ed it to my user but as soon as I mount the share, the permissions change to 755 and the user switches to root . So ho…

问题原文

原帖链接 · stdcerr · CC BY-SA 3.0

I mounted a samba share on my system to a mount point I made accessible to the world with chmod 777 and chown-ed it to my user but as soon as I mount the share, the permissions change to 755 and the user switches to root. So how can I make the share writable to my user?

已采纳解答

原帖链接 · Ryan Babchishin · CC BY-SA 3.0

The protocol deals with those permissions

You need to setup those permissions when you mount the share. See the man page for mount.cifs or the link below.

https://www.samba.org/samba/docs/man/manpages-3/mount.cifs.8.html

Specifically take note of the following

file_mode=arg If the server does not support the CIFS Unix extensions this overrides the default file mode.

dir_mode=arg If the server does not support the CIFS Unix extensions this overrides the default mode for directories.

There's also

uid=arg sets the uid that will own all files or directories on the mounted filesystem when the server does not provide ownership information. It may be specified as either a username or a numeric uid. When not specified, the default is uid 0. The mount.cifs helper must be at version 1.10 or higher to support specifying the uid in non-numeric form. See the section on FILE AND DIRECTORY OWNERSHIP AND PERMISSIONS below for more information.

forceuid instructs the client to ignore any uid provided by the server for files and directories and to always assign the owner to be the value of the uid= option. See the section on FILE AND DIRECTORY OWNERSHIP AND PERMISSIONS below for more information.

gid=arg sets the gid that will own all files or directories on the mounted filesystem when the server does not provide ownership information. It may be specified as either a groupname or a numeric gid. When not specified, the default is gid 0. The mount.cifs helper must be at version 1.10 or higher to support specifying the gid in non-numeric form. See the section on FILE AND DIRECTORY OWNERSHIP AND PERMISSIONS below for more information.

forcegid instructs the client to ignore any gid provided by the server for files and directories and to always assign the owner to be the value of the gid= option. See the section on FILE AND DIRECTORY OWNERSHIP AND PERMISSIONS below for more information.

It sounds like you want something similar to this

mount -t cifs -o username=xxx,password=xxx,file_mode=0777,dir_mode=0777 //server/share /mnt

Or you can restrict it to a specific user with something like this

mount -t cifs -o username=xxx,password=xxx,uid=1000,gid=1000 //server/share /mnt

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-08-01)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。