Difference between revisions of "Samba (简体中文)"

From ArchWiki
Jump to navigation Jump to search
(Page removed.)
(Update translation.)
 
(53 intermediate revisions by 13 users not shown)
Line 2: Line 2:
 
[[cs:Samba]]
 
[[cs:Samba]]
 
[[da:Samba]]
 
[[da:Samba]]
 +
[[de:Samba]]
 
[[en:Samba]]
 
[[en:Samba]]
 
[[es:Samba]]
 
[[es:Samba]]
 
[[fr:Samba]]
 
[[fr:Samba]]
 
[[it:Samba]]
 
[[it:Samba]]
 +
[[ja:Samba]]
 
[[ru:Samba]]
 
[[ru:Samba]]
 
[[sr:Samba]]
 
[[sr:Samba]]
[[tr:Samba]]
+
[[zh-hant:Samba]]
[[zh-TW:Samba]]
+
{{Related articles start (简体中文)}}
{{Translateme (简体中文)|文章与英文严重脱节,翻译前请先同步英文。}}
+
{{Related|NFS}}
{{Article summary start|Summary}}
+
{{Related|Samba/Active Directory domain controller}}
{{Article summary text|Samba的安装、配置和故障排除!}}
+
{{Related|Active Directory Integration}}
{{Article summary heading|Related}}
+
{{Related articles end}}
{{Article summary wiki|NFS}}
+
{{TranslationStatus (简体中文)|Samba|2019-03-13|568014}}
{{Article summary wiki|Samba Domain Controller}}
+
'''Samba''' 是 [[wikipedia:Server_Message_Block|SMB/CIFS]] 网络协议的重新实现, 可以在 Linux 和 Windows 系统间进行文件、打印机共享,和 [[NFS (简体中文)|NFS]] 的功能类似。本文介绍如何配置和使用 Samba.
{{Article summary end}}
 
'''Samba''' 是SMB/CIFS网络协议的重新实现, 它作为[[NFS (简体中文)|NFS]]的补充使得在Linux和Windows系统中进行文件共享、打印机共享更容易实现。一些用户说Samba配置简单,操作直观。然而,许多新用户会因为它的复杂性和非直观的机制而遇到问题。强烈建议新用户仔细按照下面的指导。
 
  
==安装==
+
== 服务器 ==
如果只是访问文件,而不需要共享文件,仅安装''客户端''程序就足够了.
 
# pacman -S smbclient
 
  
为了可以共享文件, 安装Samba包( 这将同时安装客户端 ):
+
=== 安装 ===
# pacman -S samba
 
  
==配置==
+
[[Pacman|安装]] 软件包 {{Pkg|samba}}
===基本配置===
 
文件 {{ic|/etc/samba/smb.conf}} 必须在守护进程运行前生成。一旦被建立起来,用户就可以选择使用SWAT这种更高级的接口来配置了。
 
  
使用root账户,拷贝默认的Samba配置文件到{{ic|/etc/samba/smb.conf}}:
+
Samba 服务的配置文件是 {{ic|/etc/samba/smb.conf}},{{man|5|smb.conf}}提供了详细的文档。
# cp /etc/samba/smb.conf.default /etc/samba/smb.conf
 
  
打开{{ic|smb.conf}}并按照你的需要编辑它。默认为每个用户的家目录生成一个共享。同时生成一个打印机共享。
+
{{Pkg|samba}} 软件包没有提供此文件,启动 ''smb''.service 前需要先创建这个文件。从 [https://git.samba.org/samba.git/?p=samba.git;a=blob_plain;f=examples/smb.conf.default;hb=HEAD 这里] 可以获取到示例文件。
  
{{ic|man smb.conf}} 查看更多可用选项。
+
从上面获取的默认配置文件里把日志{{ic|log file}}设置到一个不能写的地方, 这会引起错误。下面的办法可以解决这个问题:
 +
* 把日志文件放到可写的路径: {{ic|1=log file = /var/log/samba/%m.log}}
 +
** 把日志存到非文件后端的解决方案里: {{ic|1=logging = syslog}} 配合 {{ic|1=syslog only = yes}}, 或者使用 {{ic|1=logging = systemd}}
  
要开机自动运行samba,在 {{ic|[[rc.conf (简体中文)|rc.conf]]}} 中如下一行添加守护进程:
+
如果需要的话; 在{{ic|[global]}}部份中指定的 {{ic|workgroup}} 需要对应windows工作组的名称 (默认是 {{ic|WORKGROUP}}).
  
DAEMONS=(... ... samba ... ...)
+
{{Tip|修改 {{ic|smb.conf}} 文件后,运行 {{man|1|testparm}} 命令看看有没有语法错误。}}
  
手动管理 samba:
+
==== 配置防火墙 ====
  
# rc.d {start|stop|restart} samba
+
如果使用了 [[firewall|防火墙]],请记得打开需要的端口(通常是 137-139 + 445). 完整列表请查看 [https://www.samba.org/~tpot/articles/firewall.html Samba 端口使用]。
  
=== 基于命令行的选择 ===
+
===用户管理===
====增加用户====
 
要登入Samba共享,你应该增加一个用户.
 
  
Samba 3.4.0 的增加方法如下:
+
==== 添加用户 ====
# pdbedit -a -u <user>
+
Samba 需要 Linux 账户才能使用 - 可以使用已有账户或 [[Users and groups#User management|创建新用户]].
  
早期的方法:
+
虽然用户名可以和 Linux 系统共享,Samba 使用单独的密码管理,将下面的 {{ic|samba_user}} 替换为选择的 Samba 用户:
# smbpasswd -a <user>
 
  
存在smbpasswd数据,[[Samba#Changes_in_Samba_version_3.4.0|转换成新格式]]
+
# smbpasswd -a ''samba_user''
  
你的用户名必须是已经存在的. 如果不存在你可能得到一个错误:
+
根据 [https://www.samba.org/samba/docs/man/manpages-3/smb.conf.5.html#SERVERROLE 服务器角色] 的差异,可能需要修改已有的 [[File permissions and attributes|文件权限和属性]]。
Failed to modify password entry for user "<user>"
 
  
你可以用[[User Management#adduser|adduser]]增加一个新用户给Linux. This article does not cover adding users to Windows systems.
+
要让新创建的用户仅能访问 Samba 远程文件服务器,可以禁用其它登录选项
 +
* 禁用 shell - {{ic|usermod --shell /usr/bin/nologin --lock username}}
 +
* 禁用 SSH logons  - /etc/ssh/sshd_conf, option {{ic|AllowUsers}}
  
{{注意|smbpasswd 不再被 [[Samba#Changes_in_Samba_version_3.4.0|Samba version 3.4.0]] 默认使用。 }}
+
参阅[[Security]]
  
=== Web-based configuration (SWAT)===
+
==== 查询用户 ====
'''SWAT''' (Samba Web Administration Tool) is a facility that is part of the Samba suite. Whether or not to use this tool remains a matter of personal preference. It does allow for quick configuration and has context-sensitive help for each {{ic|smb.conf}} parameter. SWAT also provides an interface for monitoring of current state of connection(s), and  allows network-wide MS Windows network password management.
 
  
{{Warning|Before using SWAT, be warned that SWAT will completely replace {{ic|/etc/samba/smb.conf}} with a fully optimized file that has been stripped of all comments, and only non-default settings will be written to the file.}}
+
{{man|8|pdbedit}} 命令查询现有用户:
  
To use SWAT, two [[systemd]] unit files come with the samba package that allow for socket activation. The SWAT service will be called automatically should a user call on the configured socket. In this case, a TCP connection on a specific port.
+
# pdbedit -L -v
  
First, review the socket configuration:
+
==== 更改 samba 用户的密码 ====
{{hc|/usr/lib/systemd/system/swat.socket|<nowiki>
+
 
[Unit]
+
用 {{ic|smbpasswd}} 修改 samba 用户的密码:
Description=SWAT Samba Web Admin Tool
+
 
 +
# smbpasswd ''samba_user''
 +
 
 +
==== 创建共享 ====
 +
{{Note|To allow the usage of ''guests'' on public shares, one may need to [[append]] {{ic|1=map to guest = Bad User}} in the {{ic|[global]}} section of {{ic|/etc/samba/smb.conf}}. A different {{ic|1=guest account}} may be used instead of the default provided {{ic|nobody}}.}}
 +
 
 +
请确保 [https://git.samba.org/samba.git/?p=samba.git;a=blob_plain;f=examples/smb.conf.default;hb=HEAD smb.conf.default] 的 ''Share Definitions'' 部分正确设置了共享。
 +
 
 +
==== 启动服务 ====
 +
{{注意|在 {{Pkg|samba}} 4.8.0-1里, {{ic|smbd.service}} 和 {{ic|nmbd.service}} 单元被改名为 {{ic|smb.service}} 和 {{ic|nmb.service}}.}}
 +
 
 +
为了能够使用 SMB 进行基本的文件共享,[[Systemd#Using units|start/enable]] {{ic|smb.service}} 和 {{ic|nmb.service}} 服务。更多信息参阅 [http://www.samba.org/samba/docs/man/manpages-3/smbd.8.html smbd] 和 [http://www.samba.org/samba/docs/man/manpages-3/nmbd.8.html nmbd] 的 man 手册。
 +
{{ic|nmbd.service}} 并不总是需要启用。
 +
 
 +
{{提示|除了在启动时启动服务,可以选择启用 {{ic|smbd.socket}},禁用 {{ic|smbd.service}}。这样的话会在第一次收到连接请求是启动后台进程。}}
 +
 
 +
=== 高级配置 ===
 +
====建立 Usershare 路径====
 +
 
 +
{{Note|此为可选功能,如无需要可以跳过。}}
 +
 
 +
"Usershare" 让不具有 root 权限的用户可以进行添加、修改和删除自己的文件夹的操作。
 +
 
 +
以下操作将会在 {{ic|/var/lib/samba}} 添加 usershares 目录:
 +
 
 +
# mkdir -p /var/lib/samba/usershare
 +
 
 +
以下操作将会建立 sambashare 用户组:
 +
 
 +
# groupadd sambashare
 +
 
 +
以下操作将会将刚刚建立的文件夹的权限:拥有者更改为 root,群组更改为 sambashare:
 +
 
 +
# chown root:sambashare /var/lib/samba/usershare
 +
 
 +
以下的操作将会让 sambashare 群组中的用户拥有读取,写入和执行此文件夹中内容的权限:
 +
 
 +
# chmod 1770 /var/lib/samba/usershare
 +
 
 +
修改 {{ic|smb.conf}} 配置文件中的以下变量:
 +
 
 +
{{hc|/etc/samba/smb.conf|2=
 +
...
 +
[global]
 +
  usershare path = /var/lib/samba/usershare
 +
  usershare max shares = 100
 +
  usershare allow guests = yes
 +
  usershare owner only = yes
 +
  ...
 +
}}
 +
 
 +
将用户添加到群组 ''sambashare'' 中。其中,替换 {{ic|''your_username''}} 为实际的用户名:
 +
 
 +
# usermod -a -G sambashare ''your_username''
 +
 
 +
重启 {{ic|smbd.service}} 和 {{ic|nmbd.service}} 服务。
 +
 
 +
注销后重新登陆,此时您应该就可以使用 GUI 程序配置您的 samba 共享服务了。例如,在 [[Thunar]] 中您可以右键点击任何一个文件夹将它在局域网中共享。如果你想共享自己主目录内的路径,需要主目录的内容让其它用户可以列出。
 +
 
 +
== 客户端配置 ==
 +
 
 +
如果不需要查询公开的共享,可以安装轻量级的 {{Pkg|cifs-utils}} 软件包,使用 {{ic|/usr/bin/mount.cifs}} 命令挂载共享.
 +
 
 +
要使用类似 ftp 的命令行界面,请安装软件包 {{Pkg|smbclient}}。常用命令请参考 {{man|1|smbclient}}。
 +
 
 +
[[desktop environment|桌面环境]] 可能提供了图形界面,参考[[#文件管理器配置]].
 +
 
 +
{{Note|安装 {{Pkg|cifs-utils}} 或 {{Pkg|smbclient}} 后,请加载 {{ic|cifs}} [[kernel module|内核模块]] 或重启以避免挂载失败。}}
 +
 
 +
==== 显示可用共享 ====
 +
下面命令会显示服务器上的可用共享:
 +
 
 +
$ smbclient -L ''hostname'' -U%
 +
 
 +
''smbtree'' 可用显示共享目录树,不建议再有大量计算机的网络上使用此功能。可用它检查共享名是否可用。
 +
 
 +
$ smbtree -b -N
 +
 
 +
{{ic|-b}} ({{ic|--broadcast}}) 使用广播模式,{{ic|-N}} ({{ic|-no-pass}}) 不询问密码.
 +
 
 +
==== WINS 主机名====
 +
 
 +
{{pkg|smbclient}} 提供了一个用 WINS 解析主机名的驱动,要启用它,将 “wins” 添加到  /etc/nsswitch.conf 的 “hosts” 行。
 +
 
 +
==== 手动挂载 ====
 +
 
 +
创建共享挂载点:
 +
 
 +
# mkdir /mnt/''mountpoint''
 +
 
 +
使用 {{ic|mount.cifs}} 作为挂载类型 {{ic|type}},下面列出的选项并不是全部都需要:
 +
{{bc|1=
 +
# mount -t cifs //''SERVER''/''sharename'' /mnt/''mountpoint'' -o user=''username'',password=''password'',uid=''username'',gid=''group'',workgroup=''workgroup'',ip=''serverip'',iocharset=''utf8''
 +
}}
 +
 
 +
要允许用户挂载到自己可以访问的目录,请使用 {{ic|users}} 挂载选项。
 +
 
 +
{{Note|请注意这里有 '''s''',其它文件系统一般用的是 ''user''。}}
 +
使用 {{ic|uid}} 和 {{ic|gid}} 挂载选项时,请注意 [[File permissions and attributes|文件权限]],否则会出现 I/O 错误。}}
 +
 
 +
''SERVER''
 +
:  服务器名.
  
[Socket]
+
''sharename''
ListenStream=127.0.0.1:901
+
: 共享目录.
Accept=true
 
  
[Install]
+
''mountpoint''
WantedBy=sockets.target
+
: 本地的挂载点.
</nowiki>}}
 
  
{{Note|By default SWAT will only be available from the localhost, the system the SWAT service is installed on. If SWAT should be available for external connections, copy the unit to {{ic|<nowiki>/etc/systemd/system/swat.socket</nowiki>}}, and replace 127.0.0.1 with your system's LAN ip. i.e. {{ic|<nowiki>192.168.1.80:901</nowiki>}}.}}
+
{{ic|<nowiki>-o [options]</nowiki>}}
 +
: 详情请参考 {{man|8|mount.cifs}}.
  
When satisfied with the configuration, start the socket:
+
{{Note|
# systemctl start swat.socket
+
* 结尾不要加 {{ic|/}}. {{ic|//''SERVER''/''sharename'''''/'''}} 无法工作.
 +
* 如果挂载工作不稳定,出现死机和掉线问题,请尝试用 {{ic|1=vers=}} 设置不同的 SMB 协议版本。例如, 挂载 Vista 用 {{ic|1=vers=2.0}}.
 +
* 如果挂载了 cifs 机器上出现关机超时,请参考 [[WPA supplicant#Problem with mounted network shares (cifs) and shutdown]].
 +
}}
  
Or, should you want to enable SWAT during boot, enable:
+
===== 保存共享密码 =====
# systemctl enable swat.socket
 
  
The web interface can now be accessed on port 901 by default:
+
不建议将密码保存在所有人都可读的文件中,一个更安全的方式是创建密码文件:
{{ic|http://localhost:901/}}
+
{{hc|/path/to/credentials/share|2=
 +
username=''myuser''
 +
password=''mypass''
 +
}}
  
{{Note|An all-encompasing [[Webmin]] tool is also available, and the SWAT module can be loaded there.}}
+
{{ic|<nowiki>username=myuser,password=mypass</nowiki>}} 替换为 {{ic|<nowiki>credentials=/path/to/credentials/share</nowiki>}}.
  
==Accessing shares==
+
修改密码文件的权限:
Shared resources from other computers on the LAN may be accessed and mounted locally by GUI or CLI methods The graphical manner is limited.  Some Desktop Environments have a way to facilitate accessing these shared resources.  However, most do not.  In fact, most lightweight DE's and WM's offer no native method.
+
  # chmod 600 /path/to/credentials/share
  
There are two parts to share access.  First is the underlying file system mechanism, and second is the interface which allows the user to select to mount shared resources.  Some environments have the first part built into them.
+
=== Automatic mounting ===
  
If you are using KDE, it has the ability to browse Samba shares.  You therefore do not need any additional packages.  (However, for a GUI in the KDE System Settings you have to install the kdenetwork-filesharing package from [extra]. Another program choice is SMB4K.) If, however, you plan to use the share in Gnome or solely from a shell, you will need an additional package.
+
{{Note|You may need to [[enable]] {{ic|systemd-networkd-wait-online.service}} or {{ic| NetworkManager-wait-online.service}} (depending on your setup) to proper enable booting on start-up.}}
  
===从Gnome/Xfce4访问Samba共享===
+
==== As mount entry ====
为了从Nautilus访问Samba共享,你必须首先安装{{pkg|gvfs-smb}}和{{pkg|gnome-vfs}}包
 
# pacman -S gvfs-smb gnome-vfs
 
  
为了在 Xfce4 中使用 thunar 访问,只需要安装 {{pkg|gvfs-smb}}
+
This is a simple example of a {{ic|cifs}} [[fstab|mount entry]] that requires authentication:
# pacman -S gvfs-smb
 
  
在Nautilus/Thunar中, 按 {{Keypress|Ctrl}}+{{Keypress|L}} 或者点击菜单栏的 "转到" - "位置..." -- 然后在"位置:" 栏输入:
+
{{hc|/etc/fstab|2=
smb://servername/share
+
//''SERVER''/''sharename'' /mnt/''mountpoint'' cifs username=''myuser'',password=''mypass'' 0 0
 +
}}
  
{{注意|如果你的服务器名称不在 {{ic|/etc/hosts}} 中,你必须使用 IP 地址访问服务器。}}
+
{{Note|Spaces in sharename should be replaced by {{ic|\040}} (ASCII code for space in octal). For example, {{ic|//''SERVER''/share name}} on the command line should be {{ic|//''SERVER''/share\040name}} in {{ic|/etc/fstab}}.}}
  
你也可以使用另一个Gnome浏览程序Gnomba.
+
{{Tip|Use {{ic|x-systemd.automount}} if you want them to be mounted only upon access. See [[Fstab#Remote filesystem]] for details.}}
  
如果在运行 iptables ,'''nf_conntrack_netbios_ns''' 模块必须被加载:
+
==== As systemd unit ====
modprobe nf_conntrack_netbios_ns
 
  
===从其他图形环境访问共享===
+
Create a new {{ic|.mount}} file inside {{ic|/etc/systemd/system}}, e.g. {{ic|mnt-myshare.mount}}.
There are a number of useful programs, but they will need to have packages created for them. This can be done with the Arch package build system. The good thing about these others is that they do not require a particular environment to be installed to support them, and so they bring along less baggage.
 
  
LinNeighborhood is non-specific when it comes to the DE or WM. It can be seen as a simple and generic X-based LAN browser and share mounter. Not pretty, but effective.
+
{{Note|Make sure the filename corresponds to the mountpoint you want to use.
 +
E.g. the unit name {{ic|mnt-myshare.mount}} can only be used if are going to mount the share under {{ic|/mnt/myshare}}. Otherwise the following error might occur: {{ic|1=systemd[1]: mnt-myshare.mount: Where= setting does not match unit name. Refusing.}}.}}
  
Other possible programs include pyneighborhood and RUmba, as well as the xffm-samba plugin for Xffm.
+
{{ic|1=Requires=}} replace (if needed) with your [[:Category:Network configuration|Network configuration]].
  
===从命令行访问 Samba 共享===
+
{{ic|1=What=}} path to share
共享可以使用自动挂载访问,或者通过[[#手动挂载共享|手动方式]]。
 
  
====自动挂载共享====
+
{{ic|1=Where=}} path to mount the share
有很多方法可以简单的访问共享.
 
  
=====smbnetfs=====
+
{{ic|1=Options=}} share mounting options
1. 安装 {{Pkg|smbnetfs}}:
 
# pacman -S smbnetfs
 
  
2. {{ic|/etc/fuse.conf}}中添加下面内容:
+
{{Note|If you want to use a hostname for the server you want to share (instead of an IP address), add {{ic|1=systemd-resolved.service}} to {{ic|1=After}} and {{ic|1=Wants}}. This might avoid mount errors at boot time that do not arise when testing the unit.}}  
user_allow_other
 
  
3. 载入{{ic|fuse}}内核模块:
+
{{hc|/etc/systemd/system/mnt-myshare.mount|2=
# modprobe fuse
+
[Unit]
 +
Description=Mount Share at boot
 +
Requires=systemd-networkd.service
 +
After=network-online.target
 +
Wants=network-online.target
  
4. 启动 {{ic|smbnetfs}} [[daemon]]:
+
[Mount]
# /etc/rc.d/smbnetfs start
+
What=//server/share
 +
Where=/mnt/myshare
 +
Options=credentials=/etc/samba/creds/myshare,iocharset=utf8,rw,x-systemd.automount
 +
Type=cifs
 +
TimeoutSec=30
  
通过适当的配置,他就可以将所有的共享自动挂载到 {{ic|/mnt/smbnet}}下.
+
[Install]
 +
WantedBy=multi-user.target
 +
}}
  
参考如下,设置{{ic|/etc/rc.conf}}文件使其在启动时访问共享:
+
To use {{ic|mnt-myshare.mount}}, [[start]] the unit and [[enable]] it to run on system boot.
MODULES=(... '''fuse''' ...)
 
DAEMONS=(... '''smbnetfs''' ...)
 
  
如果你需要让别人输入用户名和密码来访问共享文件夹, 你需要编辑 {{ic|/etc/smbnetfs/.smb/smbnetfs.conf}}文件,取消"auth"前的注释:
+
==== smbnetfs ====
  
auth "WORKGROUP/username" "password"
+
{{Note|1=smbnetfs needs an intact Samba server setup.
 +
See above on how to do that.}}
  
然后, 你需要改变 {{ic|/etc/smbnetfs/.smb/smbnetfs.conf}} 的权限来是smbnetfs正常工作:
+
First, check if you can see all the shares you are interested in mounting:
 +
$ smbtree -U ''remote_user''
  
# chmod 600 /etc/smbnetfs/.smb/smbnetfs.conf
+
If that does not work, find and modify the following line
 +
in {{ic|/etc/samba/smb.conf}} accordingly:
  
=====fusesmb=====
+
domain master = auto
{{注意|1=因为 {{ic|smbclient 3.2.X}}和{{ic|fusesmb}}不兼容, 如果想使用fusesmb来访问共享,请将{{ic|smbclient 3.2.X}}恢复到旧的版本. 详见 [https://bbs.archlinux.org/viewtopic.php?id=58434 relevant forum topic]论坛主题.}}
 
  
1. 使用[[yaourt]]从[[AUR]]安装{{AUR|fusesmb}}包:
+
Now [[restart]] {{ic|smb.service}} and {{ic|nmb.service}}.
$ yaourt -S fusesmb
 
  
2. 创建一个挂载点:
+
If everything works as expected, [[pacman#Installing specific packages|install]] {{Pkg|smbnetfs}} from the official repositories.
# mkdir /mnt/fusesmb
 
  
3. 载入{{ic|fuse}}模块:
+
Then, add the following line to {{ic|/etc/fuse.conf}}:
# modprobe fuse
 
  
4. 挂载共享:
+
  user_allow_other
  # fusesmb -o allow_other /mnt/fusesmb
 
  
为了启动是自动挂载共享文件夹, 将以上命令增加到{{ic|/etc/rc.local}}文件中,并将{{ic|fuse}}模块增加到 {{ic|/etc/rc.conf}}:
+
Now copy the directory {{ic|/etc/smbnetfs/.smb}} to your home directory:
MODULES=(... '''fuse''' ...)
 
  
=====Autofs=====
+
$ cp -a /etc/smbnetfs/.smb ~
See [[Autofs]] for information on the kernel-based automounter for Linux.
 
  
====手动挂载共享====
+
Then create a link to {{ic|smb.conf}}:
1. Use [[smbclient]] to browse shares from the shell. To list any public shares on a server:
 
$ smbclient -L <hostname> -U%
 
  
2. 为共享创建一个挂载点:
+
$ ln -sf /etc/samba/smb.conf ~/.smb/smb.conf
# mkdir /mnt/MOUNTPOINT
 
  
3. 使用 {{ic|mount.cifs}}挂载共享. 请记住并不是所有选项都需要, 比如 {{ic|password}}:
+
If a username and a password are required to access some of the shared folders, edit {{ic|~/.smb/smbnetfs.auth}}
# mount -t cifs //''SERVER''/''SHARENAME'' ''MOUNTPOINT'' -o user=''USERNAME'',password=''PASSWORD'',workgroup=''WORKGROUP'',ip=''SERVERIP''
+
to include one or more entries like this:
  
;{{ic|SERVER}}: Windows系统的名称
+
{{hc|~/.smb/smbnetfs.auth|
;{{ic|SHARENAME}}: 共享目录
+
auth "hostname" "username" "password"
;{{ic|MOUNTPOINT}}: 希望将共享目录挂载于其上的本地目录
+
}}
;{{ic|-o [options]}}: 指定命令选项 {{ic|mount.cifs}}
 
:;{{ic|user}}: 挂载共享时所用用户名
 
:;{{ic|password}}: 共享目录的密码
 
:;{{ic|workgroup}}: 指定工作组名
 
:;{{ic|ip}}: 如果系统无法通过名字( DNS, WINS, hosts entry 等)搜索到 Windows 电脑,需要指定服务器的IP地址。
 
  
{{Note|Abstain from using trailing directory ('''/''') characters. Using {{ic|//SERVER/SHARENAME'''/'''}} will not work.}}
+
It is also possible to add entries for specific hosts to be mounted by smbnetfs, if necessary.
 +
More details can be found in {{ic|~/.smb/smbnetfs.conf}}.
  
4. 可以用下面的命令卸载共享:
+
If you are using the [[Dolphin]] or [[GNOME Files]], you may want to add the following to {{ic|~/.smb/smbnetfs.conf}} to avoid "Disk full" errors as smbnetfs by default will report 0 bytes of free space:
# umount /mnt/MOUNTPOINT
 
  
=====添加共享到 {{ic|fstab}}=====
+
{{hc|~/.smb/smbnetfs.conf|
为了方便地使用共享,可以添加下面的内容到 {{ic|/etc/[[fstab]]}} :
+
free_space_size 1073741824
//SERVER/SHARENAME /mnt/MOUNTPOINT cifs noauto,noatime,username=USER,password=PASSWORD,workgroup=WORKGROUP 0 0
+
}}
  
The {{ic|noauto}} option disables mounting it automatically at boot and {{ic|noatime}} increases performance by skipping inode access times.
+
When you are done with the configuration, you need to run
  
After adding the previous line, the syntax to mount files becomes simpler:
+
  $ chmod 600 ~/.smb/smbnetfs.*
  # mount /mnt/MOUNTPOINT
 
  
=====Allowing users to mount=====
+
Otherwise, smbnetfs complains about 'insecure config file permissions'.
Before enabling access to the mount commands, {{ic|fstab}} needs to be modified. Add the {{ic|users}} options to the entry in {{ic|/etc/fstab}}:
 
//SERVER/SHARENAME /path/to/SHAREMOUNT cifs '''users''',noauto,noatime,username=USER,password=PASSWORD,workgroup=WORKGROUP 0 0
 
  
{{Note|The option is {{ic|user'''s'''}} (plural). For other filesystem types handled by mount, this option is usually  ''user''; sans the "'''s'''".}}
+
Finally, to mount your Samba network neighbourhood to a directory of your choice, call
  
This will allow users to mount it aslong as the mount point resides in a directory ''controllable'' by the user; i.e. the user's home. For users to be allowed to mount and unmount the Samba shares with mount points that they do not own, use [[#smbnetfs]], or grant privileges using [[sudo]].
+
$ smbnetfs ''mount_point''
  
== Tips and tricks ==
+
===== Daemon =====
  
=== Share files for your LAN without user and password ===
+
The Arch Linux package also maintains an additional system-wide operation mode for smbnetfs. To enable it, you need to make the
 +
said modifications in the directoy {{ic|/etc/smbnetfs/.smb}}.
  
Edit {{ic|/etc/samba/smb.conf}} and add the following line:
+
Then, you can start and/or enable the {{ic|smbnetfs}} [[daemon]] as usual. The system-wide mount point is at {{ic|/mnt/smbnet/}}.
  
map to guest = Bad User
+
==== autofs ====
  
After this line
+
See [[Autofs]] for information on the kernel-based automounter for Linux.
  
security = user
+
=== File manager configuration ===
  
If you want to restrict the shares data to a specific interface replace:
+
==== GNOME Files, Nemo, Caja, Thunar and PCManFM ====
  
;  interfaces = 192.168.12.2/24 192.168.13.2/24
+
In order to access samba shares through GNOME Files, Nemo, Caja, Thunar or PCManFM, install the {{Pkg|gvfs-smb}} package, available in the [[official repositories]].
  
with:
+
Press {{ic|Ctrl+l}} and enter {{ic|smb://''servername''/''share''}} in the location bar to access your share.
  
interfaces = lo eth0
+
The mounted share is likely to be present at {{ic|/run/user/''your_UID''/gvfs}} or {{ic|~/.gvfs}} in the filesystem.
bind interfaces only = true
 
  
(changing eth0 to the local network you want share with.)
+
==== KDE ====
  
If you want to edit the account that access the shares, edit the following line:
+
KDE has the ability to browse Samba shares built in. To use a GUI in the KDE System Settings, you will need to install the {{Pkg|kdenetwork-filesharing}} package.
  
;  guest account = nobody
+
If you get a "Time Out" Error when navigating with Dolphin, you should uncomment and edit the following line in smb.conf:{{bc|1=name resolve order = lmhosts bcast host wins}}
 +
as shown in this [http://ubuntuforums.org/showthread.php?t=1605499 page].
  
The last step is to create share directory (for write access make writable = yes):
+
==== Other graphical environments ====
  
[Public Share]
+
There are a number of useful programs, but they may need to have packages created for them. This can be done with the Arch package build system. The good thing about these others is that they do not require a particular environment to be installed to support them, and so they bring along less baggage.
path = /path/to/public/share
 
available = yes
 
browsable = yes
 
public = yes
 
writable = no
 
  
=== Sample configuration file ===
+
* {{Pkg|pyneighborhood}} is available in the official repositories.
 +
* LinNeighborhood, RUmba, xffm-samba plugin for Xffm are not available in the official repositories or the AUR. As they are not officially (or even unofficially supported), they may be obsolete and may not work at all.
  
The configuration that worked for one user:
+
== Tips and tricks ==
[global]
 
workgroup = WORKGROUP
 
server string = Samba Server
 
netbios name = PC_NAME
 
security = share
 
; the line below is important! If you have permission issues make
 
; sure the user here is the same as the user of the folder you
 
; want to share
 
guest account = mark
 
username map = /etc/samba/smbusers
 
name resolve order = hosts wins bcast
 
wins support = no<br />
 
[public]
 
comment = Public Share
 
path = /path/to/public/share
 
available = yes
 
browsable = yes
 
public = yes
 
writable = no
 
  
 
=== Discovering network shares ===
 
=== Discovering network shares ===
  
If nothing is known about other systems on the local network, and automated tools such as [[#smbnetfs]] are not available, the following methods allow one to manually probe for Samba shares.
+
If nothing is known about other systems on the local network, and automated tools such as [[#smbnetfs|smbnetfs]] are not available, the following methods allow one to manually probe for Samba shares.
  
1. First, install {{Pkg|nmap}} and {{Pkg|smbclient}} using [[pacman]]:
+
1. First, [[install]] the {{Pkg|nmap}} and {{Pkg|smbclient}} packages.
# pacman -S nmap smbclient
 
  
 
2. {{ic|nmap}} checks which ports are open:
 
2. {{ic|nmap}} checks which ports are open:
# nmap -sT 192.168.1.*
 
  
In this case, a scan on the 192.168.1.* IP address range has been performed, resulting in:
+
# nmap -p 139 -sT "192.168.1.*"
{{hc
+
 
|$ nmap -sT 192.168.1.*
+
In this case, a scan on the 192.168.1.* IP address range and port 139 has been performed, resulting in:
|Starting nmap 3.78 ( http://www.insecure.org/nmap/ ) at 2005-02-15 11:45 PHT
+
 
 +
{{hc|$ nmap -sT "192.168.1.*"|
 +
Starting nmap 3.78 ( http://www.insecure.org/nmap/ ) at 2005-02-15 11:45 PHT
 
Interesting ports on 192.168.1.1:
 
Interesting ports on 192.168.1.1:
 
(The 1661 ports scanned but not shown below are in state: closed)
 
(The 1661 ports scanned but not shown below are in state: closed)
Line 312: Line 373:
 
The first result is another system; the second happens to be the client from where this scan was performed.
 
The first result is another system; the second happens to be the client from where this scan was performed.
  
3. Now that systems with port 139 open are revealed, use {{ic|nmblookup}} to check for NetBIOS names:  
+
3. Now that systems with port 139 open are revealed, use {{man|1|nmblookup}} to check for NetBIOS names:  
{{hc
+
 
|$ nmblookup -A 192.168.1.1
+
{{hc|$ nmblookup -A 192.168.1.1|
|Looking up status of 192.168.1.1
+
Looking up status of 192.168.1.1
 
         PUTER          <00> -        B <ACTIVE>
 
         PUTER          <00> -        B <ACTIVE>
 
         HOMENET        <00> - <GROUP> B <ACTIVE>
 
         HOMENET        <00> - <GROUP> B <ACTIVE>
Line 329: Line 390:
  
 
4. Use {{ic|smbclient}} to list which services are shared on ''PUTER''. If prompted for a password, pressing enter should still display the list:
 
4. Use {{ic|smbclient}} to list which services are shared on ''PUTER''. If prompted for a password, pressing enter should still display the list:
{{hc
+
 
|$ smbclient -L \\PUTER
+
{{hc|$ smbclient -L \\PUTER|2=
|<nowiki>
 
 
Sharename      Type      Comment
 
Sharename      Type      Comment
 
---------      ----      -------
 
---------      ----      -------
Line 347: Line 407:
 
---------            -------
 
---------            -------
 
HOMENET              PUTER
 
HOMENET              PUTER
</nowiki>}}
+
}}
 
 
This shows which folders are shared and can be mounted locally. See: [[#Accessing Samba shares]]
 
  
 
=== Remote control of Windows computer ===
 
=== Remote control of Windows computer ===
  
Samba offers a set of tools for communication with Windows. These can be handy in case you can't access a Windows computer through remote desktop, as shown by some examples.
+
Samba offers a set of tools for communication with Windows. These can be handy if access to a Windows computer through remote desktop is not an option, as shown by some examples.
  
 
Send shutdown command with a comment:
 
Send shutdown command with a comment:
 
   
 
   
 
  $ net rpc shutdown -C "comment" -I IPADDRESS -U USERNAME%PASSWORD
 
  $ net rpc shutdown -C "comment" -I IPADDRESS -U USERNAME%PASSWORD
If you prefer a forced shutdown instead change -C with comment to a single -f. For a restart you only add -r, followed by a -C or -f.
+
 
 +
A forced shutdown instead can be invoked by changing -C with comment to a single -f. For a restart, only add -r, followed by a -C or -f.
  
 
Stop and start services:
 
Stop and start services:
Line 369: Line 428:
  
 
== Troubleshooting ==
 
== Troubleshooting ==
=== Trouble accessing a password-protected share from Windows ===
 
  
If you are having trouble accessing a password protected share from Windows, try adding this to {{ic|/etc/samba/smb.conf}}:[http://blogs.computerworld.com/networking_nightmare_ii_adding_linux]
+
=== Failed to start Samba SMB/CIFS server ===
 +
 
 +
Possible solutions:
 +
 
 +
* Check {{ic|smb.conf}} on syntactic errors with {{man|1|testparm}}.
 +
* Set correct permissions for {{ic|/var/cache/samba/}} and [[restart]] {{ic|smb.service}}:
 +
 
 +
# chmod 0755 /var/cache/samba/msg
 +
 
 +
=== Permission issues on AppArmor ===
 +
 
 +
If using a [[#Creating a share|share path]] located outside of a home-directory, whitelist it in {{ic|/etc/apparmor.d/local/usr.sbin.smbd}}. E.g.:
 +
 
 +
{{hc|/etc/apparmor.d/local/usr.sbin.smbd|
 +
/data/** lrwk,
 +
}}
 +
 
 +
=== No dialect specified on mount ===
 +
 
 +
The client is using an unsupported SMB/CIFS version that is required by the server.
 +
 
 +
See [[#Restrict protocols for better security]] for more information.
 +
 
 +
=== Unable to overwrite files, permissions errors ===
 +
 
 +
{{Accuracy|An user should set/check for server/client permissions, instead of using incorrect/possible insecure flags.}}
 +
 
 +
Possible solutions:
 +
 
 +
* Append the mount option {{ic|nodfs}} to the {{ic|/etc/fstab}} [[#As mount entry|entry]].
 +
* Add {{ic|1=msdfs root = no}} to the {{ic|[global]}} section of the server's {{ic|/etc/samba/smb.conf}}.
 +
 
 +
=== Windows clients keep asking for password even if Samba shares are created with guest permissions ===
 +
 
 +
Set {{ic|map to guest}} inside the {{ic|global}} section of {{ic|/etc/samba/smb.conf}}:
  
Note that you have to add this to your '''local''' smb.conf, not to the server's smb.conf
+
map to guest = Bad User
  
[global]
+
=== Windows 7 connectivity problems - mount error(12): cannot allocate memory ===
# lanman fix
 
client lanman auth = yes
 
client ntlmv2 auth = no
 
  
=== Getting a dialog box up takes a long time ===
+
A known Windows 7 bug that causes "mount error(12): cannot allocate memory" on an otherwise perfect cifs share on the Linux end can be fixed by setting a few registry keys on the Windows box as follows:
  
I had a problem that it took ~30 seconds to get a password dialog box up when trying to connect from both Windows XP/Windows 7. Analyzing the error.log on the server I saw:
+
* {{ic|HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\LargeSystemCache}} (set to {{ic|1}})
 +
* {{ic|HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\Size}} (set to {{ic|3}})
  
[2009/11/11 06:20:12, 0] printing/print_cups.c:cups_connect(103)
+
Alternatively, start Command Prompt in Admin Mode and execute the following:
Unable to connect to CUPS server localhost:631 - Interrupted system call
 
  
I don't have any printer connected to this server, so I added this to the global section:
+
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" /v "LargeSystemCache" /t REG_DWORD /d 1 /f
 +
reg add "HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters" /v "Size" /t REG_DWORD /d 3 /f
  
  load printers = no
+
Do one of the following for the settings to take effect:
printing = bsd
+
 
disable spoolss = yes
+
* Restart Windows
  printcap name = /dev/null
+
* Restart the Server service via services.msc
 +
* From the Command Prompt run: 'net stop lanmanserver' and 'net start lanmanserver' - The server may automatically restart after stopping it.
 +
 
 +
{{Note|Googling will reveal another tweak recommending users to add a key modifying the "IRPStackSize" size.  This is incorrect for fixing this issue under Windows 7.  Do not attempt it.}}
 +
 
 +
[http://alan.lamielle.net/2009/09/03/windows-7-nonpaged-pool-srv-error-2017 Original article].
 +
 
 +
=== Windows 10 1709 and up connectivity problems - "Windows cannot access" 0x80004005 ===
 +
 
 +
This error affects some machines running Windows 10 version 1709 and later. It is not related to SMB1 being disabled in this version but to the fact that Microsoft disabled insecure logons for guests on this version for some, but not others.
 +
 
 +
To fix, open Group Policy Editor ({{ic|gpedit.msc}}). Navigate to ''Computer configuration\administrative templates\network\Lanman Workstation > Enable insecure guest logons'' and enable it.
 +
Alternatively,change the following value in the registry:
 +
 
 +
  [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanWorkstation\Parameters]
 +
"AllowInsecureGuestAuth"=dword:1
 +
 
 +
=== Error: Failed to retrieve printer list: NT_STATUS_UNSUCCESSFUL ===
 +
 
 +
If you are a home user and using samba purely for file sharing from a server or NAS, you are probably not interested in sharing printers through it. If so, you can prevent this error from occurring by adding the following lines to your {{ic|/etc/samba/smb.conf}}:
 +
 
 +
{{hc|/etc/samba/smb.conf|2=
 +
[global]
 +
  load printers = No
 +
  printing = bsd
 +
  printcap name = /dev/null
 +
  disable spoolss = Yes
 +
}}
 +
 
 +
[[Restart]] the samba service, {{ic|smb.service}}, and then check your logs:
 +
 
 +
  # cat /var/log/samba/smbd.log
 +
 
 +
and the error should now no longer be appearing.
 +
 
 +
=== Sharing a folder fails  ===
 +
 
 +
It means that while you are sharing a folder from ''Dolphin'' (file manager) and everything seems ok at first, after restarting ''Dolphin'' the share icon is gone from the shared folder, and also some output like this in terminal (''Konsole'') output:
 +
 
 +
‘net usershare’ returned error 255: net usershare: usershares are currently disabled
 +
 
 +
To fix it, enable usershare as described in [[#Enable usershares]].
 +
 
 +
=== "Browsing" network fails with "Failed to retrieve share list from server" ===
 +
 
 +
And you are using a firewall (iptables) because you do not trust your local (school, university, hotel) network.  This may be due to the following: When the smbclient is browsing the local network it sends out a broadcast request on udp port 137.  The servers on the network then reply to your client but as the source address of this reply is different from the destination address iptables saw when sending the request for the listing out, iptables will not recognize the reply as being "ESTABLISHED" or "RELATED", and hence the packet is dropped.  A possible solution is to add:
 +
 
 +
iptables -t raw -A OUTPUT -p udp -m udp --dport 137 -j CT --helper netbios-ns
 +
 
 +
to your iptables setup.
 +
 
 +
=== Protocol negotiation failed: NT_STATUS_INVALID_NETWORK_RESPONSE ===
 +
 
 +
The client probably does not have access to shares.  Make sure clients' IP address is in {{ic|1=hosts allow =}} line in {{ic|/etc/samba/smb.conf}}.
 +
 
 +
Another problem could be, that the client uses an invalid protocol version. To check this try to connect with the {{ic|smbclient}} where you specify the maximum protocol version manually:
 +
 
 +
$ smbclient -U <user name> -L //<server name> -m <protocol version: e. g. SMB2> -W <domain name>
 +
 
 +
If the command was successful then create a configuration file:
 +
 
 +
{{hc|~/.smb/smb.conf|output=
 +
[global]
 +
  workgroup = <domain name>
 +
  client max protocol = SMB2
 +
}}
 +
 
 +
=== Connection to SERVER failed: (Error NT_STATUS_UNSUCCESSFUL) ===
 +
 
 +
You are probably passing a wrong server name to {{ic|smbclient}}.  To find out the server name, run {{ic|hostnamectl}} on the server and look at "Transient hostname" line
 +
 
 +
=== Connection to SERVER failed: (Error NT_STATUS_CONNECTION_REFUSED) ===
 +
 
 +
Make sure that the server has started. The shared directories should exist and be accessible.
 +
 
 +
=== Protocol negotiation failed: NT_STATUS_CONNECTION_RESET ===
 +
 
 +
Probably the server is configured not to accept protocol SMB1. Add option {{ic|1=client max protocol = SMB2}} in {{ic|/etc/samba/smb.conf}}.
 +
Or just pass argument {{ic|-m SMB2}} to {{ic|smbclient}}.
 +
 
 +
=== Password Error when correct credentials are given (error 1326) ===
 +
 
 +
[https://www.samba.org/samba/history/samba-4.5.0.html Samba 4.5] has NTLMv1 authentication disabled by default. It is recommend to install the latest available upgrades on clients and deny access for unsupported clients.
 
   
 
   
Not sure if all of them are necessary, but at least it works now.
+
If you still need support for very old clients without NTLMv2 support (e.g. Windows XP), it is possible force enable NTLMv1, although this is '''not recommend''' for security reasons:
 +
 
 +
{{hc|/etc/samba/smb.conf|2=
 +
[global]
 +
  lanman auth = yes
 +
  ntlm auth = yes
 +
}}
 +
 
 +
If NTLMv2 clients are unable to authenticate when NTLMv1 has been enabled, create the following file on the client:
 +
{{hc|/home/user/.smb/smb.conf|2=
 +
[global]
 +
  sec = ntlmv2
 +
  client ntlmv2 auth = yes
 +
}}
 +
 
 +
This change also affects samba shares mounted with '''mount.cifs'''. If after upgrade to Samba 4.5 your mount fails, add the '''sec=ntlmssp''' option to your mount command, e.g.
 +
 
 +
mount.cifs //server/share /mnt/point -o sec=ntlmssp,...
 +
 
 +
See the {{man|8|mount.cifs}} man page: '''ntlmssp''' - Use NTLMv2 password hashing encapsulated in Raw NTLMSSP message. The default in mainline kernel versions prior to v3.8 was '''sec=ntlm'''. In v3.8, the default was changed to '''sec=ntlmssp'''.
 +
 
 +
=== Mapping reserved Windows characters ===
 +
 
 +
Starting with kernel 3.18, the cifs module uses the [https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=2baa2682531ff02928e2d3904800696d9e7193db "mapposix" option by default].
 +
When mounting a share using unix extensions and a default Samba configuration, files and directories containing one of the seven reserved Windows characters {{ic|: \ * < > ? |}} are listed but cannot be accessed.
 +
 
 +
Possible solutions are:
 +
 
 +
* Use the undocumented {{ic|nomapposix}} mount option for cifs
 +
 
 +
  # mount.cifs //server/share /mnt/point -o nomapposix
 +
 
 +
* Configure Samba to remap {{ic|mapposix}} ("SFM", Services for Mac) style characters to the correct native ones using [https://www.mankier.com/8/vfs_fruit fruit]
 +
 
 +
{{hc|/etc/samba/smb.conf|2=
 +
[global]
 +
  vfs objects = catia fruit
 +
  fruit:encoding = native
 +
}}
 +
 
 +
* Manually remap forbidden characters using [https://www.mankier.com/8/vfs_catia catia]
 +
 
 +
{{hc|/etc/samba/smb.conf|2=
 +
[global]
 +
  vfs objects = catia
 +
  catia:mappings = 0x22:0xf022, 0x2a:0xf02a, 0x2f:0xf02f, 0x3a:0xf03a, 0x3c:0xf03c, 0x3e:0xf03e, 0x3f:0xf03f, 0x5c:0xf05c, 0x7c:0xf07c, 0x20:0xf020
 +
}}
 +
 
 +
The latter approach (using catia or fruit) has the drawback of filtering files with unprintable characters.
 +
 
 +
=== Folder shared inside graphical environment is not available to guests ===
 +
 
 +
This section presupposes:
 +
 
 +
# Usershares are configured following [[#Enable usershares|previous section]]
 +
# A shared folder has been created as a non-root user from GUI
 +
# Guests access has been set to shared folder during creation
 +
# Samba service has been restarted at least once since last {{ic|/etc/samba/smb.conf}} file modification
 +
 
 +
For clarification purpose only, in the following sub-sections is assumed:
 +
 
 +
* Shared folder is located inside user home directory path ({{ic|/home/yourUser/Shared}})
 +
* Shared folder name is ''MySharedFiles''
 +
* Guest access is read-only.
 +
* Windows users will access shared folder content without login prompt
 +
 
 +
==== Verify correct samba configuration ====
 +
 
 +
Run the following command from a terminal to test configuration file correctness:
 +
 
 +
$ testparm
 +
 
 +
==== Verify correct shared folder creation ====
 +
 
 +
Run the following commands from a terminal:
 +
 
 +
$ cd /var/lib/samba/usershare
 +
$ ls
 +
 
 +
If everything is fine, you will notice a file named {{ic|mysharedfiles}}
 +
 
 +
Read the file contents using the following command:
 +
 
 +
$ cat mysharedfiles
 +
 
 +
The terminal output should display something like this:
 +
 
 +
{{hc|/var/lib/samba/usershare/mysharedfiles|2=
 +
path=/home/yourUser/Shared
 +
comment=
 +
usershare_acl=S-1-1-0:r
 +
guest_ok=y
 +
sharename=MySharedFiles
 +
}}
 +
 
 +
==== Verify folder access by guest ====
 +
 
 +
Run the following command from a terminal. If prompted for a password, just press Enter:
 +
 
 +
$ smbclient -L localhost
  
=== Changes in Samba version 3.4.0 ===
+
If everything is fine, MySharedFiles should be displayed under {{ic|Sharename}} column
  
[http://www.samba.org/samba/history/samba-3.4.0.html Major enhancements in Samba 3.4.0] include:
+
Run the following command in order to access the shared folder as guest (anonymous login)
  
The default passdb backend has been changed to 'tdbsam'! That breaks existing setups using the 'smbpasswd' backend without explicit declaration!
+
$ smbclient -N //localhost/MySharedFiles
  
If you would like to stick to the 'smbpasswd' backend try changing this in {{ic|/etc/samba/smb.conf}}:
+
If everything is fine samba client prompt will be displayed:
  
  passdb backend = smbpasswd
+
  smb: \>
  
or convert your smbpasswd entries using:
+
From samba prompt verify guest can list directory contents:
  
  sudo pdbedit -i smbpasswd -e tdbsam
+
  smb: \> ls
  
=== Error: Value too large for defined data type ===
+
If {{ic|NTFS_STATUS_ACCESS_DENIED}} error displayed, probably there is something to be solved at directory permission level.
  
With some applications you could get this error whith every attempt to open a file mounted in smbfs/cifs:
+
Run the following commands as root to set correct permissions for folders:
  
  Value too large for defined data type
+
# cd /home
 +
# chmod -R 755 /home/yourUser/Shared
  
The solution[https://bugs.launchpad.net/ubuntu/+bug/479266/comments/5] is to add this options to your smbfs/cifs mount options (in /etc/fstab for example):
+
Access shared folder again as guest to be sure guest read access error has been solved.
  
  ,nounix,noserverino
+
=== Mount error: Host is down ===
 +
This error might be seen when mounting shares of Synology NAS servers. Use the mount option {{ic|1=vers=1.0}} to solve it.
  
''It works on Arch Linux up-to-date (2009-12-02)''
+
== See also ==
  
== Resources ==
+
* [https://www.samba.org/ Official website]
*[http://www.samba.org/ Samba's official site]
+
* [https://www.samba.org/samba/docs/SambaIntro.html Samba: An Introduction]
*[http://www.samba.org/samba/docs/SambaIntro.html Samba: An Introduction]
+
* [https://www.samba.org/samba/docs/Samba-HOWTO-Collection.pdf Samba 3.2.x HOWTO and Reference Guide] (outdated but still most extensive documentation)
 +
* [[Wikipedia:Samba (software)|Wikipedia]]
 +
* [[Gentoo:Samba/Guide]]
 +
* [[Debian:SambaServerSimple]]

Latest revision as of 09:00, 13 March 2019

翻译状态: 本文是英文页面 Samba翻译,最后翻译时间:2019-03-13,点击这里可以查看翻译后英文页面的改动。

SambaSMB/CIFS 网络协议的重新实现, 可以在 Linux 和 Windows 系统间进行文件、打印机共享,和 NFS 的功能类似。本文介绍如何配置和使用 Samba.

Contents

服务器

安装

安装 软件包 samba

Samba 服务的配置文件是 /etc/samba/smb.confsmb.conf(5)提供了详细的文档。

samba 软件包没有提供此文件,启动 smb.service 前需要先创建这个文件。从 这里 可以获取到示例文件。

从上面获取的默认配置文件里把日志log file设置到一个不能写的地方, 这会引起错误。下面的办法可以解决这个问题:

  • 把日志文件放到可写的路径: log file = /var/log/samba/%m.log
    • 把日志存到非文件后端的解决方案里: logging = syslog 配合 syslog only = yes, 或者使用 logging = systemd

如果需要的话; 在[global]部份中指定的 workgroup 需要对应windows工作组的名称 (默认是 WORKGROUP).

Tip: 修改 smb.conf 文件后,运行 testparm(1) 命令看看有没有语法错误。

配置防火墙

如果使用了 防火墙,请记得打开需要的端口(通常是 137-139 + 445). 完整列表请查看 Samba 端口使用

用户管理

添加用户

Samba 需要 Linux 账户才能使用 - 可以使用已有账户或 创建新用户.

虽然用户名可以和 Linux 系统共享,Samba 使用单独的密码管理,将下面的 samba_user 替换为选择的 Samba 用户:

# smbpasswd -a samba_user

根据 服务器角色 的差异,可能需要修改已有的 文件权限和属性

要让新创建的用户仅能访问 Samba 远程文件服务器,可以禁用其它登录选项

  • 禁用 shell - usermod --shell /usr/bin/nologin --lock username
  • 禁用 SSH logons - /etc/ssh/sshd_conf, option AllowUsers

参阅Security

查询用户

pdbedit(8) 命令查询现有用户:

# pdbedit -L -v

更改 samba 用户的密码

smbpasswd 修改 samba 用户的密码:

# smbpasswd samba_user

创建共享

Note: To allow the usage of guests on public shares, one may need to append map to guest = Bad User in the [global] section of /etc/samba/smb.conf. A different guest account may be used instead of the default provided nobody.

请确保 smb.conf.defaultShare Definitions 部分正确设置了共享。

启动服务

注意: samba 4.8.0-1里, smbd.servicenmbd.service 单元被改名为 smb.servicenmb.service.

为了能够使用 SMB 进行基本的文件共享,start/enable smb.servicenmb.service 服务。更多信息参阅 smbdnmbd 的 man 手册。 nmbd.service 并不总是需要启用。

提示: 除了在启动时启动服务,可以选择启用 smbd.socket,禁用 smbd.service。这样的话会在第一次收到连接请求是启动后台进程。

高级配置

建立 Usershare 路径

Note: 此为可选功能,如无需要可以跳过。

"Usershare" 让不具有 root 权限的用户可以进行添加、修改和删除自己的文件夹的操作。

以下操作将会在 /var/lib/samba 添加 usershares 目录:

# mkdir -p /var/lib/samba/usershare

以下操作将会建立 sambashare 用户组:

# groupadd sambashare

以下操作将会将刚刚建立的文件夹的权限:拥有者更改为 root,群组更改为 sambashare:

# chown root:sambashare /var/lib/samba/usershare

以下的操作将会让 sambashare 群组中的用户拥有读取,写入和执行此文件夹中内容的权限:

# chmod 1770 /var/lib/samba/usershare

修改 smb.conf 配置文件中的以下变量:

/etc/samba/smb.conf
...
[global]
  usershare path = /var/lib/samba/usershare
  usershare max shares = 100
  usershare allow guests = yes
  usershare owner only = yes
  ...

将用户添加到群组 sambashare 中。其中,替换 your_username 为实际的用户名:

# usermod -a -G sambashare your_username

重启 smbd.servicenmbd.service 服务。

注销后重新登陆,此时您应该就可以使用 GUI 程序配置您的 samba 共享服务了。例如,在 Thunar 中您可以右键点击任何一个文件夹将它在局域网中共享。如果你想共享自己主目录内的路径,需要主目录的内容让其它用户可以列出。

客户端配置

如果不需要查询公开的共享,可以安装轻量级的 cifs-utils 软件包,使用 /usr/bin/mount.cifs 命令挂载共享.

要使用类似 ftp 的命令行界面,请安装软件包 smbclient。常用命令请参考 smbclient(1)

桌面环境 可能提供了图形界面,参考#文件管理器配置.

Note: 安装 cifs-utilssmbclient 后,请加载 cifs 内核模块 或重启以避免挂载失败。

显示可用共享

下面命令会显示服务器上的可用共享:

$ smbclient -L hostname -U%

smbtree 可用显示共享目录树,不建议再有大量计算机的网络上使用此功能。可用它检查共享名是否可用。

$ smbtree -b -N

-b (--broadcast) 使用广播模式,-N (-no-pass) 不询问密码.

WINS 主机名

smbclient 提供了一个用 WINS 解析主机名的驱动,要启用它,将 “wins” 添加到 /etc/nsswitch.conf 的 “hosts” 行。

手动挂载

创建共享挂载点:

# mkdir /mnt/mountpoint

使用 mount.cifs 作为挂载类型 type,下面列出的选项并不是全部都需要:

# mount -t cifs //SERVER/sharename /mnt/mountpoint -o user=username,password=password,uid=username,gid=group,workgroup=workgroup,ip=serverip,iocharset=utf8

要允许用户挂载到自己可以访问的目录,请使用 users 挂载选项。

Note: 请注意这里有 s,其它文件系统一般用的是 user

使用 uidgid 挂载选项时,请注意 文件权限,否则会出现 I/O 错误。}}

SERVER

服务器名.

sharename

共享目录.

mountpoint

本地的挂载点.

-o [options]

详情请参考 mount.cifs(8).
Note:
保存共享密码

不建议将密码保存在所有人都可读的文件中,一个更安全的方式是创建密码文件:

/path/to/credentials/share
username=myuser
password=mypass

username=myuser,password=mypass 替换为 credentials=/path/to/credentials/share.

修改密码文件的权限:

# chmod 600 /path/to/credentials/share

Automatic mounting

Note: You may need to enable systemd-networkd-wait-online.service or NetworkManager-wait-online.service (depending on your setup) to proper enable booting on start-up.

As mount entry

This is a simple example of a cifs mount entry that requires authentication:

/etc/fstab
//SERVER/sharename /mnt/mountpoint cifs username=myuser,password=mypass 0 0
Note: Spaces in sharename should be replaced by \040 (ASCII code for space in octal). For example, //SERVER/share name on the command line should be //SERVER/share\040name in /etc/fstab.
Tip: Use x-systemd.automount if you want them to be mounted only upon access. See Fstab#Remote filesystem for details.

As systemd unit

Create a new .mount file inside /etc/systemd/system, e.g. mnt-myshare.mount.

Note: Make sure the filename corresponds to the mountpoint you want to use. E.g. the unit name mnt-myshare.mount can only be used if are going to mount the share under /mnt/myshare. Otherwise the following error might occur: systemd[1]: mnt-myshare.mount: Where= setting does not match unit name. Refusing..

Requires= replace (if needed) with your Network configuration.

What= path to share

Where= path to mount the share

Options= share mounting options

Note: If you want to use a hostname for the server you want to share (instead of an IP address), add systemd-resolved.service to After and Wants. This might avoid mount errors at boot time that do not arise when testing the unit.
/etc/systemd/system/mnt-myshare.mount
[Unit]
Description=Mount Share at boot
Requires=systemd-networkd.service
After=network-online.target
Wants=network-online.target

[Mount]
What=//server/share
Where=/mnt/myshare
Options=credentials=/etc/samba/creds/myshare,iocharset=utf8,rw,x-systemd.automount
Type=cifs
TimeoutSec=30

[Install]
WantedBy=multi-user.target

To use mnt-myshare.mount, start the unit and enable it to run on system boot.

smbnetfs

Note: smbnetfs needs an intact Samba server setup. See above on how to do that.

First, check if you can see all the shares you are interested in mounting:

$ smbtree -U remote_user

If that does not work, find and modify the following line in /etc/samba/smb.conf accordingly:

domain master = auto

Now restart smb.service and nmb.service.

If everything works as expected, install smbnetfs from the official repositories.

Then, add the following line to /etc/fuse.conf:

user_allow_other

Now copy the directory /etc/smbnetfs/.smb to your home directory:

$ cp -a /etc/smbnetfs/.smb ~

Then create a link to smb.conf:

$ ln -sf /etc/samba/smb.conf ~/.smb/smb.conf

If a username and a password are required to access some of the shared folders, edit ~/.smb/smbnetfs.auth to include one or more entries like this:

~/.smb/smbnetfs.auth
auth			"hostname" "username" "password"

It is also possible to add entries for specific hosts to be mounted by smbnetfs, if necessary. More details can be found in ~/.smb/smbnetfs.conf.

If you are using the Dolphin or GNOME Files, you may want to add the following to ~/.smb/smbnetfs.conf to avoid "Disk full" errors as smbnetfs by default will report 0 bytes of free space:

~/.smb/smbnetfs.conf
free_space_size 1073741824

When you are done with the configuration, you need to run

$ chmod 600 ~/.smb/smbnetfs.*

Otherwise, smbnetfs complains about 'insecure config file permissions'.

Finally, to mount your Samba network neighbourhood to a directory of your choice, call

$ smbnetfs mount_point
Daemon

The Arch Linux package also maintains an additional system-wide operation mode for smbnetfs. To enable it, you need to make the said modifications in the directoy /etc/smbnetfs/.smb.

Then, you can start and/or enable the smbnetfs daemon as usual. The system-wide mount point is at /mnt/smbnet/.

autofs

See Autofs for information on the kernel-based automounter for Linux.

File manager configuration

GNOME Files, Nemo, Caja, Thunar and PCManFM

In order to access samba shares through GNOME Files, Nemo, Caja, Thunar or PCManFM, install the gvfs-smb package, available in the official repositories.

Press Ctrl+l and enter smb://servername/share in the location bar to access your share.

The mounted share is likely to be present at /run/user/your_UID/gvfs or ~/.gvfs in the filesystem.

KDE

KDE has the ability to browse Samba shares built in. To use a GUI in the KDE System Settings, you will need to install the kdenetwork-filesharing package.

If you get a "Time Out" Error when navigating with Dolphin, you should uncomment and edit the following line in smb.conf:

name resolve order = lmhosts bcast host wins

as shown in this page.

Other graphical environments

There are a number of useful programs, but they may need to have packages created for them. This can be done with the Arch package build system. The good thing about these others is that they do not require a particular environment to be installed to support them, and so they bring along less baggage.

  • pyneighborhood is available in the official repositories.
  • LinNeighborhood, RUmba, xffm-samba plugin for Xffm are not available in the official repositories or the AUR. As they are not officially (or even unofficially supported), they may be obsolete and may not work at all.

Tips and tricks

Discovering network shares

If nothing is known about other systems on the local network, and automated tools such as smbnetfs are not available, the following methods allow one to manually probe for Samba shares.

1. First, install the nmap and smbclient packages.

2. nmap checks which ports are open:

# nmap -p 139 -sT "192.168.1.*"

In this case, a scan on the 192.168.1.* IP address range and port 139 has been performed, resulting in:

$ nmap -sT "192.168.1.*"
Starting nmap 3.78 ( http://www.insecure.org/nmap/ ) at 2005-02-15 11:45 PHT
Interesting ports on 192.168.1.1:
(The 1661 ports scanned but not shown below are in state: closed)
PORT     STATE SERVICE
139/tcp  open  netbios-ssn
5000/tcp open  UPnP

Interesting ports on 192.168.1.5:
(The 1662 ports scanned but not shown below are in state: closed)
PORT     STATE SERVICE
6000/tcp open  X11

Nmap run completed -- 256 IP addresses (2 hosts up) scanned in 7.255 seconds

The first result is another system; the second happens to be the client from where this scan was performed.

3. Now that systems with port 139 open are revealed, use nmblookup(1) to check for NetBIOS names:

$ nmblookup -A 192.168.1.1
Looking up status of 192.168.1.1
        PUTER           <00> -         B <ACTIVE>
        HOMENET         <00> - <GROUP> B <ACTIVE>
        PUTER           <03> -         B <ACTIVE>
        PUTER           <20> -         B <ACTIVE>
        HOMENET         <1e> - <GROUP> B <ACTIVE>
        USERNAME        <03> -         B <ACTIVE>
        HOMENET         <1d> -         B <ACTIVE>
        MSBROWSE        <01> - <GROUP> B <ACTIVE>

Regardless of the output, look for <20>, which shows the host with open services.

4. Use smbclient to list which services are shared on PUTER. If prompted for a password, pressing enter should still display the list:

$ smbclient -L \\PUTER
Sharename       Type      Comment

---- ------- MY_MUSIC Disk SHAREDDOCS Disk PRINTER$ Disk PRINTER Printer IPC$ IPC Remote Inter Process Communication Server Comment
------- PUTER Workgroup Master
------- HOMENET PUTER

Remote control of Windows computer

Samba offers a set of tools for communication with Windows. These can be handy if access to a Windows computer through remote desktop is not an option, as shown by some examples.

Send shutdown command with a comment:

$ net rpc shutdown -C "comment" -I IPADDRESS -U USERNAME%PASSWORD

A forced shutdown instead can be invoked by changing -C with comment to a single -f. For a restart, only add -r, followed by a -C or -f.

Stop and start services:

$ net rpc service stop SERVICENAME -I IPADDRESS -U USERNAME%PASSWORD

To see all possible net rpc command:

$ net rpc

Troubleshooting

Failed to start Samba SMB/CIFS server

Possible solutions:

  • Check smb.conf on syntactic errors with testparm(1).
  • Set correct permissions for /var/cache/samba/ and restart smb.service:
# chmod 0755 /var/cache/samba/msg

Permission issues on AppArmor

If using a share path located outside of a home-directory, whitelist it in /etc/apparmor.d/local/usr.sbin.smbd. E.g.:

/etc/apparmor.d/local/usr.sbin.smbd
/data/** lrwk,

No dialect specified on mount

The client is using an unsupported SMB/CIFS version that is required by the server.

See #Restrict protocols for better security for more information.

Unable to overwrite files, permissions errors

Tango-inaccurate.pngThe factual accuracy of this article or section is disputed.Tango-inaccurate.png

Reason: An user should set/check for server/client permissions, instead of using incorrect/possible insecure flags. (Discuss in Talk:Samba (简体中文)#)

Possible solutions:

  • Append the mount option nodfs to the /etc/fstab entry.
  • Add msdfs root = no to the [global] section of the server's /etc/samba/smb.conf.

Windows clients keep asking for password even if Samba shares are created with guest permissions

Set map to guest inside the global section of /etc/samba/smb.conf:

map to guest = Bad User

Windows 7 connectivity problems - mount error(12): cannot allocate memory

A known Windows 7 bug that causes "mount error(12): cannot allocate memory" on an otherwise perfect cifs share on the Linux end can be fixed by setting a few registry keys on the Windows box as follows:

  • HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\LargeSystemCache (set to 1)
  • HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\Size (set to 3)

Alternatively, start Command Prompt in Admin Mode and execute the following:

reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" /v "LargeSystemCache" /t REG_DWORD /d 1 /f
reg add "HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters" /v "Size" /t REG_DWORD /d 3 /f

Do one of the following for the settings to take effect:

  • Restart Windows
  • Restart the Server service via services.msc
  • From the Command Prompt run: 'net stop lanmanserver' and 'net start lanmanserver' - The server may automatically restart after stopping it.
Note: Googling will reveal another tweak recommending users to add a key modifying the "IRPStackSize" size. This is incorrect for fixing this issue under Windows 7. Do not attempt it.

Original article.

Windows 10 1709 and up connectivity problems - "Windows cannot access" 0x80004005

This error affects some machines running Windows 10 version 1709 and later. It is not related to SMB1 being disabled in this version but to the fact that Microsoft disabled insecure logons for guests on this version for some, but not others.

To fix, open Group Policy Editor (gpedit.msc). Navigate to Computer configuration\administrative templates\network\Lanman Workstation > Enable insecure guest logons and enable it. Alternatively,change the following value in the registry:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanWorkstation\Parameters]
"AllowInsecureGuestAuth"=dword:1

Error: Failed to retrieve printer list: NT_STATUS_UNSUCCESSFUL

If you are a home user and using samba purely for file sharing from a server or NAS, you are probably not interested in sharing printers through it. If so, you can prevent this error from occurring by adding the following lines to your /etc/samba/smb.conf:

/etc/samba/smb.conf
[global]
  load printers = No
  printing = bsd
  printcap name = /dev/null
  disable spoolss = Yes

Restart the samba service, smb.service, and then check your logs:

# cat /var/log/samba/smbd.log

and the error should now no longer be appearing.

Sharing a folder fails

It means that while you are sharing a folder from Dolphin (file manager) and everything seems ok at first, after restarting Dolphin the share icon is gone from the shared folder, and also some output like this in terminal (Konsole) output:

‘net usershare’ returned error 255: net usershare: usershares are currently disabled

To fix it, enable usershare as described in #Enable usershares.

"Browsing" network fails with "Failed to retrieve share list from server"

And you are using a firewall (iptables) because you do not trust your local (school, university, hotel) network. This may be due to the following: When the smbclient is browsing the local network it sends out a broadcast request on udp port 137. The servers on the network then reply to your client but as the source address of this reply is different from the destination address iptables saw when sending the request for the listing out, iptables will not recognize the reply as being "ESTABLISHED" or "RELATED", and hence the packet is dropped. A possible solution is to add:

iptables -t raw -A OUTPUT -p udp -m udp --dport 137 -j CT --helper netbios-ns

to your iptables setup.

Protocol negotiation failed: NT_STATUS_INVALID_NETWORK_RESPONSE

The client probably does not have access to shares. Make sure clients' IP address is in hosts allow = line in /etc/samba/smb.conf.

Another problem could be, that the client uses an invalid protocol version. To check this try to connect with the smbclient where you specify the maximum protocol version manually:

$ smbclient -U <user name> -L //<server name> -m <protocol version: e. g. SMB2> -W <domain name>

If the command was successful then create a configuration file:

~/.smb/smb.conf
[global]
  workgroup = <domain name>
  client max protocol = SMB2

Connection to SERVER failed: (Error NT_STATUS_UNSUCCESSFUL)

You are probably passing a wrong server name to smbclient. To find out the server name, run hostnamectl on the server and look at "Transient hostname" line

Connection to SERVER failed: (Error NT_STATUS_CONNECTION_REFUSED)

Make sure that the server has started. The shared directories should exist and be accessible.

Protocol negotiation failed: NT_STATUS_CONNECTION_RESET

Probably the server is configured not to accept protocol SMB1. Add option client max protocol = SMB2 in /etc/samba/smb.conf. Or just pass argument -m SMB2 to smbclient.

Password Error when correct credentials are given (error 1326)

Samba 4.5 has NTLMv1 authentication disabled by default. It is recommend to install the latest available upgrades on clients and deny access for unsupported clients.

If you still need support for very old clients without NTLMv2 support (e.g. Windows XP), it is possible force enable NTLMv1, although this is not recommend for security reasons:

/etc/samba/smb.conf
[global]
  lanman auth = yes
  ntlm auth = yes

If NTLMv2 clients are unable to authenticate when NTLMv1 has been enabled, create the following file on the client:

/home/user/.smb/smb.conf
[global]
  sec = ntlmv2
  client ntlmv2 auth = yes

This change also affects samba shares mounted with mount.cifs. If after upgrade to Samba 4.5 your mount fails, add the sec=ntlmssp option to your mount command, e.g.

mount.cifs //server/share /mnt/point -o sec=ntlmssp,...

See the mount.cifs(8) man page: ntlmssp - Use NTLMv2 password hashing encapsulated in Raw NTLMSSP message. The default in mainline kernel versions prior to v3.8 was sec=ntlm. In v3.8, the default was changed to sec=ntlmssp.

Mapping reserved Windows characters

Starting with kernel 3.18, the cifs module uses the "mapposix" option by default. When mounting a share using unix extensions and a default Samba configuration, files and directories containing one of the seven reserved Windows characters : \ * < > ? are listed but cannot be accessed.

Possible solutions are:

  • Use the undocumented nomapposix mount option for cifs
 # mount.cifs //server/share /mnt/point -o nomapposix
  • Configure Samba to remap mapposix ("SFM", Services for Mac) style characters to the correct native ones using fruit
/etc/samba/smb.conf
[global]
  vfs objects = catia fruit
  fruit:encoding = native
  • Manually remap forbidden characters using catia
/etc/samba/smb.conf
[global]
  vfs objects = catia
  catia:mappings = 0x22:0xf022, 0x2a:0xf02a, 0x2f:0xf02f, 0x3a:0xf03a, 0x3c:0xf03c, 0x3e:0xf03e, 0x3f:0xf03f, 0x5c:0xf05c, 0x7c:0xf07c, 0x20:0xf020

The latter approach (using catia or fruit) has the drawback of filtering files with unprintable characters.

Folder shared inside graphical environment is not available to guests

This section presupposes:

  1. Usershares are configured following previous section
  2. A shared folder has been created as a non-root user from GUI
  3. Guests access has been set to shared folder during creation
  4. Samba service has been restarted at least once since last /etc/samba/smb.conf file modification

For clarification purpose only, in the following sub-sections is assumed:

  • Shared folder is located inside user home directory path (/home/yourUser/Shared)
  • Shared folder name is MySharedFiles
  • Guest access is read-only.
  • Windows users will access shared folder content without login prompt

Verify correct samba configuration

Run the following command from a terminal to test configuration file correctness:

$ testparm

Verify correct shared folder creation

Run the following commands from a terminal:

$ cd /var/lib/samba/usershare
$ ls

If everything is fine, you will notice a file named mysharedfiles

Read the file contents using the following command:

$ cat mysharedfiles

The terminal output should display something like this:

/var/lib/samba/usershare/mysharedfiles
path=/home/yourUser/Shared
comment=
usershare_acl=S-1-1-0:r
guest_ok=y
sharename=MySharedFiles

Verify folder access by guest

Run the following command from a terminal. If prompted for a password, just press Enter:

$ smbclient -L localhost

If everything is fine, MySharedFiles should be displayed under Sharename column

Run the following command in order to access the shared folder as guest (anonymous login)

$ smbclient -N //localhost/MySharedFiles

If everything is fine samba client prompt will be displayed:

smb: \>

From samba prompt verify guest can list directory contents:

smb: \> ls

If NTFS_STATUS_ACCESS_DENIED error displayed, probably there is something to be solved at directory permission level.

Run the following commands as root to set correct permissions for folders:

# cd /home
# chmod -R 755 /home/yourUser/Shared

Access shared folder again as guest to be sure guest read access error has been solved.

Mount error: Host is down

This error might be seen when mounting shares of Synology NAS servers. Use the mount option vers=1.0 to solve it.

See also