Samba
Samba 是用於Linux和Unix的標準Windows互操作性程序套件。自1992年以來,Samba為所有使用 SMB/CIFS 協議的客户提供了安全、穩定和快速的文件和打印服務,例如所有版本的DOS和Windows、OS/2、Linux和許多其他系統。
要通過Samba共享文件,請參閱#伺服器部分;要訪問其他機器上通過Samba共享的文件,請參見#客户端部分。
伺服器[編輯 | 編輯原始碼]
安裝[編輯 | 編輯原始碼]
Samba 服務的配置文件是 /etc/samba/smb.conf
,smb.conf(5)提供了詳細的文檔。
samba包 軟件包沒有提供此文件,啟動 smb.service
前需要先創建這個文件。從 Samba 的 Git 倉庫 可以獲取到示例文件smb.conf.default
。
- 從上面獲取的默認配置文件裡把日誌
log file
設置到一個不能寫的地方,,這會引起錯誤。下面的辦法可以解決這個問題:- 把日誌文件放到可寫的路徑:
log file = /var/log/samba/%m.log
- 把日誌存到非文件後端的解決方案裡:
logging = syslog
配合syslog only = yes
,或者使用logging = systemd
- 把日誌文件放到可寫的路徑:
- 如果需要的話;在
[global]
部份中指定的workgroup
需要對應 Windows 工作組的名稱 (默認是WORKGROUP
)。
smb.conf
文件後,運行 testparm(1) 命令看看有沒有語法錯誤。配置防火牆[編輯 | 編輯原始碼]
如果使用了 防火牆,請記得打開需要的端口(通常是 137-139 + 445). 完整列表請查看 Samba 端口使用。
使伺服器可被發現[編輯 | 編輯原始碼]
安裝 avahi包 軟件包, 然後啟用/啟動 avahi-daemon.service
以通過 Zeroconf 使 Samba 伺服器可被發現。這應當在多數非 Windows 文件管理器上可用(macOS Finder,Linux 和 BSD 上各種基於GUI的文件管理器,等等)。
如果avahi-daemon.service
尚未運行,伺服器仍可被訪問,僅不可被發現,也就是説,它不會出現在文件管理器中,但你仍可直接通過 IP 或者域名連接它。
Windows 資源管理器依賴 WS-Directory 協議而非此;參見 #Windows 1709 及更高版本無法在「網絡」視圖中發現 Samba 伺服器。
用户管理[編輯 | 編輯原始碼]
添加用户[編輯 | 編輯原始碼]
Samba 需要 Linux 賬户才能使用 - 可以使用已有賬户或 創建新用户.
雖然用户名可以和 Linux 系統共享,Samba 使用單獨的密碼管理,將下面的 samba_user
替換為選擇的 Samba 用户:
# smbpasswd -a samba_user
根據 伺服器角色 的差異,可能需要修改已有的 文件權限和屬性。
要讓新創建的用户僅能訪問 Samba 遠程文件伺服器,可以禁用其它登錄選項
- 禁用 shell -
usermod --shell /usr/bin/nologin --lock samba_user
- 禁用 SSH logons - /etc/ssh/sshd_config, option
AllowUsers
參閱 Security。
查詢用户[編輯 | 編輯原始碼]
用 pdbedit(8) 命令查詢現有用户:
# pdbedit -L -v
更改 samba 用户的密碼[編輯 | 編輯原始碼]
用 smbpasswd
修改 samba 用户的密碼:
# smbpasswd samba_user
創建共享[編輯 | 編輯原始碼]
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.default 的 Share Definitions 部分正確設置了共享。
啟動服務[編輯 | 編輯原始碼]
為了能夠使用 SMB 進行基本的文件共享,start/enable smb.service
和 nmb.service
服務。更多信息參閱 smbd 和 nmbd 的 man 手冊。
nmb.service
並不總是需要啟用。
smbd.socket
,禁用 smb.service
。這樣的話會在第一次收到連接請求時啟動後台進程。高級配置[編輯 | 編輯原始碼]
[編輯 | 編輯原始碼]
Usershares 讓不具有 root 權限的用户可以進行添加、修改和刪除自己的文件夾的操作。參見 samba.conf(5) § USERSHARES。
以下操作將會在 /var/lib/samba
添加 usershares 目錄:
# mkdir /var/lib/samba/usershares
以下操作將會建立 sambashare 用户組:
# groupadd sambashare
以下操作將會將剛剛建立的文件夾的權限:擁有者更改為 root,羣組更改為 sambashare:
# chown root:sambashare /var/lib/samba/usershares
以下的操作將會讓 sambashare 羣組中的用户擁有讀取,寫入和執行此文件夾中內容的權限:
# chmod 1770 /var/lib/samba/usershares
修改 smb.conf
配置文件中的以下變量:
/etc/samba/smb.conf
... [global] usershare path = /var/lib/samba/usershares usershare max shares = 100 usershare allow guests = yes usershare owner only = yes ...
將用户添加到羣組 sambashare 中。其中,替換 your_username
為實際的用户名:
# usermod -a -G sambashare your_username
重啟 smb.service
和 nmb.service
服務。
註銷後重新登錄,此時您應該就可以使用 GUI 程序配置您的 samba 共享服務了。例如,在 Thunar 中您可以右鍵點擊任何一個文件夾將它在局域網中共享。如果你想共享自己主目錄內的路徑,需要主目錄的內容讓其它用户可以列出。
在命令行中,請使用下面命令,替換掉 sharename, user, ... :
# net usershare add sharename abspath [comment] [user:{R|D|F}] [guest_ok={y|n}] # net usershare delete sharename # net usershare list wildcard-sharename # net usershare info wildcard-sharename
設置/強制設置權限[編輯 | 編輯原始碼]
權限可同時應用於伺服器和共享:
/etc/samba/smb.conf
[global] ;inherit owner = unix only ; Inherit ownership of the parent directory for new files and directories ;inherit permissions = yes ; Inherit permissions of the parent directory for new files and directories create mask = 0664 directory mask = 2755 force create mode = 0644 force directory mode = 2755 ... [media] comment = Media share accessible by greg and pcusers path = /path/to/media valid users = greg @pcusers force group = +pcusers public = no writable = yes create mask = 0664 directory mask = 2775 force create mode = 0664 force directory mode = 2775 [public] comment = Public share where archie has write access path = /path/to/public public = yes read only = yes write list = archie printable = no [guests] comment = Allow all users to read/write path = /path/to/guests public = yes only guest = yes writable = yes printable = no
參見 smb.conf(5) 查看完整的可用權限標誌和設置。
限制協議以增強安全性[編輯 | 編輯原始碼]
server min protocol = SMB2_02
以保護自己免遭勒索軟件攻擊。在Samba 4.11及更新版本,SMB2已是默認最低協議,因此不再需要此更改。在 /etc/samba/smb.conf
中加入 server min protocol
和 server max protocol
以強制使用最小和最大版本協議;
/etc/samba/smb.conf
[global] server min protocol = SMB2_02 ; server max protocol = SMB3
參見 smb.conf(5) 中的server max protocol
部分以獲取所支持協議的概述。
為了和舊版本的客户端和/或伺服器兼容,你或許需要設置 client min protocol = CORE
或 server min protocol = CORE
,但請注意這將會使你易於遭受利用SMB1的攻擊,包括勒索軟件攻擊。
server min protocol = SMB3_00
,例如,Windows 8 及之後版本。使用 mount.cifs
的客户端也許需要指定正確的 vers=*
,例如:
# mount -t cifs //SERVER/sharename /mnt/mountpoint -o username=username,password=password,iocharset=utf8,vers=3.1.1
參見 mount.cifs(8) 獲取更多信息.
使用原生 SMB 傳輸加密[編輯 | 編輯原始碼]
原生 SMB 傳輸加密在 SMB 3.0 及更新版本可用。支持該類型加密的客户端包括 Windows 8 以及更新版本,Windows Server 2012 及更新版本,以及 Samba 4.1 及更新版本的 smbclient。
為了默認使用原生 SMB 傳輸加密,全局和/或按共享設置 smb encrypt
參數。可能的值有off
, enabled
(默認值), desired
, 或 required
:
/etc/samba/smb.conf
[global] smb encrypt = desired
參見 smb.conf(5) 獲取更多信息,特別是 對 SMB1 的影響 和 對 SMB2 的影響 的段落。
seal
掛載選項以強制使用加密。禁用打印機共享[編輯 | 編輯原始碼]
默認情況下 Samba 共享由 CUPS 設置的打印機。
如果你不想打印機被共享,使用以下設置:
/etc/samba/smb.conf
[global] load printers = no printing = bsd printcap name = /dev/null disable spoolss = yes show add printer wizard = no
封鎖 Samba 共享中的特定文件後綴[編輯 | 編輯原始碼]
Samba 提供了一個選項以封鎖特定模式的文件,比如文件擴展名。該選項可用於防止病毒傳播或阻止用户用特定的文件浪費空間。更多關於此選項的信息可在 smb.conf(5) 找到。
/etc/samba/smb.conf
... [myshare] comment = Private path = /mnt/data read only = no veto files = /*.exe/*.com/*.dll/*.bat/*.vbs/*.tmp/*.mp3/*.avi/*.mp4/*.wmv/*.wma/
Improve throughput[編輯 | 編輯原始碼]
The default settings should be sufficient for most users. However setting the 'socket options' correct can improve performance, but getting them wrong can degrade it by just as much. Test the effect before making any large changes.
Read the smb.conf(5) man page before applying any of the options listed below.
The following settings should be append to the [global]
section of /etc/samba/smb.conf
.
SMB3 multi-channel may improve performance, however it may result in data corruption under some race conditions. Future releases may improve this situation:
server multi channel support = yes
Setting a deadtime is useful to stop a server's resources being exhausted by a large number of inactive connections:
deadtime = 30
The usage of sendfile may make more efficient use of the system CPU's and cause Samba to be faster:
use sendfile = yes
The write cache allows Samba to batch client writes into a more efficient write size for RAID disks (i.e. writes may be tuned to be the RAID stripe size) and can improve performance on systems where the disk subsystem is a bottleneck but there is free memory for userspace programs:
write cache size = 262144
Setting min receivefile size allows zero-copy writes directly from network socket buffers into the filesystem buffer cache (if available). It may improve performance but user testing is recommended:
min receivefile size = 16384
Reading/writing files asynchronously may improve performance instead of using synchronously writes:
aio read size = 1 aio write size = 1
Increasing the receive/send buffers size and socket optimize flags might be useful to improve throughput. It is recommended to test each flag separately as it may cause issues on some networks:
socket options = IPTOS_LOWDELAY TCP_NODELAY IPTOS_THROUGHPUT SO_RCVBUF=131072 SO_SNDBUF=131072
客户端配置[編輯 | 編輯原始碼]
如果不需要查詢公開的共享,可以安裝輕量級的 cifs-utils包 軟件包,使用 /usr/bin/mount.cifs
命令掛載共享.
要使用類似 ftp 的命令行界面,請安裝軟件包 smbclient包。常用命令請參考 smbclient(1)。
顯示可用共享[編輯 | 編輯原始碼]
下面命令會顯示伺服器上的可用共享:
$ 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
掛載選項。
使用 uid
和 gid
掛載選項時,請注意 文件權限,否则会出现 I/O 错误。}}
SERVER
- 伺服器名.
sharename
- 共享目錄.
mountpoint
- 本地的掛載點.
-o [options]
- 詳情請參考 mount.cifs(8).
- 結尾不要加
/
.//SERVER/sharename/
無法工作. - 如果掛載工作不穩定,出現死機和掉線問題,請嘗試用
vers=
設置不同的 SMB 協議版本。例如, 掛載 Vista 用vers=2.0
. - 如果掛載了 cifs 機器上出現關機超時,請參考 wpa_supplicant#Problem with mounted network shares (cifs) and shutdown.
保存共享密碼[編輯 | 編輯原始碼]
不建議將密碼保存在所有人都可讀的文件中,一個更安全的方式是創建密碼文件:
/path/to/credentials/share
username=myuser password=mypass
將 username=myuser,password=mypass
替換為 credentials=/path/to/credentials/share
.
修改密碼文件的權限:
# chmod 600 /path/to/credentials/share
自動掛載[編輯 | 編輯原始碼]
systemd-networkd-wait-online.service
or NetworkManager-wait-online.service
(depending on your setup) to proper enable booting on start-up.作為掛載路徑[編輯 | 編輯原始碼]
This is a simple example of a cifs
mount entry that requires authentication:
/etc/fstab
//SERVER/sharename /mnt/mountpoint cifs _netdev,username=myuser,password=mypass 0 0
\040
(ASCII code for space in octal). For example, //SERVER/share name
on the command line should be //SERVER/share\040name
in /etc/fstab
.x-systemd.automount
if you want them to be mounted only upon access. See Fstab#Remote file system for details.作為系統單元[編輯 | 編輯原始碼]
Create a new .mount
file inside /etc/systemd/system
, e.g. mnt-myshare.mount
. See systemd.mount(5) for details.
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.
.What=
path to share
Where=
path to mount the share
Options=
share mounting options
- Network mount units automatically acquire
After
dependencies on remote-fs-pre.target, network.target and network-online.target, and gain aBefore
dependency on remote-fs.target unlessnofail
mount option is set. Towards the latter aWants
unit is added as well. - Append
noauto
toOptions
preventing automatically mount during boot (unless it is pulled in by some other unit). - If you want to use a hostname for the server you want to share (instead of an IP address), add
nss-lookup.target
toAfter
andWants
. 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 [Mount] What=//server/share Where=/mnt/myshare Options=_netdev,credentials=/etc/samba/credentials/myshare,iocharset=utf8,rw Type=cifs TimeoutSec=30 [Install] WantedBy=multi-user.target
ForceUnmount=true
to [Mount]
, allowing the share to be (force-)unmounted.To use mnt-myshare.mount
, start the unit and enable it to run on system boot.
automount[編輯 | 編輯原始碼]
To automatically mount a share, one may use the following automount unit:
/etc/systemd/system/mnt-myshare.automount
[Unit] Description=Automount myshare [Automount] Where=/mnt/myshare [Install] WantedBy=multi-user.target
Disable/stop the mnt-myshare.mount
unit, and enable/start mnt-myshare.automount
to automount the share when the mount path is being accessed.
smbnetfs[編輯 | 編輯原始碼]
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 directory /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.
文件管理器配置[編輯 | 編輯原始碼]
GNOME 文件、Nemo、Caja、Thunar 和 PCManFM[編輯 | 編輯原始碼]
為了通過 GNOME 文件,Nemo,Caja,Thunar 或 PCManFM 訪問 samba 共享,安裝 gvfs-smb包 軟件包,其在官方倉庫可用。
按 Ctrl+l
然後在位置欄鍵入 smb://servername/share
以訪問您的共享。
掛載的共享可能存在於文件系統中的/run/user/your_UID/gvfs
或 ~/.gvfs
。
KDE[編輯 | 編輯原始碼]
KDE 有內建的瀏覽 Samba 共享的能力。為了使用 KDE 系統設置的 GUI,你需要安裝 kdenetwork-filesharing包 軟件包。
如果你在通過 Dolphin 瀏覽時遇到「超時」錯誤,你需要取消註釋並修改 smb.conf 中的以下行:
name resolve order = lmhosts bcast host wins
按照 此頁 所述。
其它圖形環境[編輯 | 編輯原始碼]
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.
- pyneighborhoodAUR 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.
提示與技巧[編輯 | 編輯原始碼]
[編輯 | 編輯原始碼]
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
疑難解答[編輯 | 編輯原始碼]
啟動 Samba SMB/CIFS 伺服器失敗[編輯 | 編輯原始碼]
可能的解決方法:
- 通過 testparm(1) 檢查
smb.conf
中的符號問題。 - 在
/var/cache/samba/
中設置正確的權限然後重啟smb.service
:
# chmod 0755 /var/cache/samba/msg
SELinux 權限問題[編輯 | 編輯原始碼]
SELinux 默認不允許 samba 訪問用户的家目錄。為了解決此問題,運行:
# setsebool -P samba_enable_home_dirs 1
類似地,samba_export_all_ro
和 samba_export_all_rw
使 Samba 擁有讀取或「讀和寫」所有文件的能力。
AppArmor 權限問題[編輯 | 編輯原始碼]
如果使用了一個在家目錄之外的共享路徑,請在 /etc/apparmor.d/local/usr.sbin.smbd
中將其加入白名單。例如:
/etc/apparmor.d/local/usr.sbin.smbd
"/data/" rk, "/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[編輯 | 編輯原始碼]
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
.
[編輯 | 編輯原始碼]
Set map to guest
inside the global
section of /etc/samba/smb.conf
:
map to guest = Bad User
From Samba 4.10.10 you should use Bad Password
instead 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 to1
)HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\Size
(set to3
)
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.
Windows 10 1709 和更高版本的連接性問題 - "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 #建立 Usershare 路徑.
[編輯 | 編輯原始碼]
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.
[編輯 | 編輯原始碼]
This section presupposes:
- Usershares are configured following 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
/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
[編輯 | 編輯原始碼]
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.
Software caused connection abort[編輯 | 編輯原始碼]
File managers that utilizes gvfs-smb包 can show the error Software caused connection abort
when writing a file to a share/server. This may be due to the server running SMB/CIFS version 1, which many routers use for USB drive sharing (e.g. Belkin routers). To write to these shares specify the CIFS version with the option vers=1.0
. E.g.:
/etc/fstab
//SERVER/sharename /mnt/mountpoint cifs _netdev,guest,file_mode=0777,dir_mode=0777,vers=1.0 0 0
This can also happen after updating Samba to version 4.11, which deactivates SMB1 as default, and accessing any Samba share. You can reenable it by adding
/etc/samba/smb.conf
[global] client min protocol = CORE
Connection problem (due to authentification error)[編輯 | 編輯原始碼]
Be sure that you do not leave any space characters before your username in Samba client configuration file as follows:
~/.samba
username= user password=pass
The correct format is:
~/.samba
username=user password=pass
Windows 1709 及更高版本無法在「網絡」視圖中發現 Samba 伺服器[編輯 | 編輯原始碼]
隨着Windows 10 1511版本的推出,對SMBv1的支持以及由此的NetBIOS設備發現被默認禁用。根據實際的版本,從1709版本("秋季創意者更新")開始的後期Windows版本不允許再安裝SMBv1客户端。這導致運行Samba的主機不能在資源管理器的 "網絡(網上鄰居)"視圖中列出。雖然並無連接問題,而且Samba仍然可以正常運行,但用户可能想讓他們的Samba主機被Windows自動列出。wsddAUR 實現了一個 Web Service Discovery 宿主守護進程。這使得(Samba)主機,比方説你的本地NAS設備,能夠被像Windows這樣的Web服務發現客户端找到。默認設置應該適用於大多數安裝,你所需要做的就是啟動/啟用 wsdd.service
。
默認配置(在組 "WORKGROUP "中使用機器主機名公示自己)在大多數情況下應該是你所需要的全部。如果你有需要,你可以通過在 /etc/conf.d/wsdd
中添加額外的參數來改變配置選項(詳見wsdd的手冊頁)。
wsdd2AUR完成同樣的工作,但它是用 C 語言而不是 Python 編寫的。默認情況下,它將在 smb.conf
中尋找 netbios name
和 workgroup
值。
更多參考[編輯 | 編輯原始碼]
- Official website
- Samba: An Introduction
- Samba 3.2.x HOWTO and Reference Guide (outdated but still most extensive documentation)
- Wikipedia
- Gentoo:Samba/Guide
- Debian:SambaServerSimple