Difference between revisions of "Samba"

From ArchWiki
Jump to navigation Jump to search
m (remove contractions)
(→‎Restrict protocols for better security: emphasize dangers of SMB1, note changes upcoming next week in Samba 4.11, which will disable SMB1 by default)
 
(528 intermediate revisions by more than 100 users not shown)
Line 1: Line 1:
[[Category:Networking (English)]]
+
[[Category:Network sharing]]
{{i18n|Samba}}
+
[[Category:Servers]]
 +
[[cs:Samba]]
 +
[[da:Samba]]
 +
[[de:Samba]]
 +
[[es:Samba]]
 
[[fr:Samba]]
 
[[fr:Samba]]
{{Article summary start|Summary}}
+
[[it:Samba]]
{{Article summary text|Installing, configuring and troubleshooting Samba}}
+
[[ja:Samba]]
{{Article summary heading|Related}}
+
[[ru:Samba]]
{{Article summary wiki|NFS}}
+
[[sr:Samba]]
{{Article summary wiki|Samba Domain Controller}}
+
[[zh-hans:Samba]]
{{Article summary end}}
+
[[zh-hant:Samba]]
 +
{{Related articles start}}
 +
{{Related|Active Directory Integration}}
 +
{{Related|Samba/Active Directory domain controller}}
 +
{{Related|NFS}}
 +
{{Related articles end}}
  
'''Samba''' is a re-implementation of the SMB/CIFS networking protocol, it facilitates file and printer sharing among Linux and Windows systems as an alternative to [[NFS]]. Some users say that Samba is easily configured and that operation is very straight-forward.  However, many new users run into problems with its complexity and non-intuitive mechanism.  It is strongly suggested that the user stick close to the following directions.
+
[https://www.samba.org/ Samba] is a re-implementation of the [[wikipedia:Server_Message_Block|SMB]] networking protocol. It facilitates file and printer sharing among Linux and Windows systems as an alternative to [[NFS]]. This article provides instructions for users on how to setup Samba.
  
==Installation==
+
== Server ==
Installing only the ''client'' program is sufficient for systems that are not meant to share files, only access them:
 
# pacman -S smbclient
 
  
In order to make shares available to clients, install the Samba ''server'' package (which will also install the smbclient):
+
=== Installation ===
# pacman -S samba
 
  
A daemon is installed with the server and it must be started for Samba to begin working. Samba typically uses [[FAM]] to monitor the file-system for changes, yet it can also use [[Gamin]], as Gamin has almost completely replaced FAM recently, mainly because FAM is poorly maintained and generally an inferior, unpopular choice.
+
[[Install]] the {{Pkg|samba}} package.
  
To install Gamin:
+
Samba is configured in the {{ic|/etc/samba/smb.conf}} configuration file, which is extensively documented in {{man|5|smb.conf}}.
# pacman -S gamin
 
  
==Configuration==
+
Because the {{Pkg|samba}} package does not provide this file, one needs to create it '''before''' starting ''smb''.service.
The {{filename|/etc/samba/smb.conf}} file must be created before starting the daemons. Once that is set up, users may opt for using an advanced configuration interface like SWAT.
 
  
===smb.conf===
+
A documented example as in {{ic|smb.conf.default}} from the [https://git.samba.org/samba.git/?p=samba.git;a=blob_plain;f=examples/smb.conf.default;hb=HEAD Samba git repository] may be used to setup {{ic|/etc/samba/smb.conf}}.
As root, copy the default Samba configuration file to {{Filename|/etc/samba/smb.conf}}:
 
# cp /etc/samba/smb.conf.default /etc/samba/smb.conf
 
  
Open {{Filename|smb.conf}} and edit it to suit your needs. The default file creates a share for each user's home directory. It also creates a share for printers.
+
{{Note|
 +
*The default configuration sets {{ic|log file}} to a non-writable location, which will cause errors - apply one of the following workarounds:
 +
** Change the log file location to a writable path: {{ic|1=log file = /var/log/samba/%m.log}}
 +
** Change logging to a non-file backend solution: {{ic|1=logging = syslog}} with {{ic|1=syslog only = yes}}, or use {{ic|1=logging = systemd}}
 +
*If required; the {{ic|workgroup}} specified in the {{ic|[global]}} section has to match the Windows workgroup (default {{ic|WORKGROUP}}).
 +
}}
 +
 
 +
{{Tip|Whenever you modify the {{ic|smb.conf}} file, run the {{man|1|testparm}} command to check for syntactic errors.}}
 +
 
 +
==== Configure Firewall ====
 +
 
 +
If you are using a [[firewall]], do not forget to open required ports (usually 137-139 + 445). For a complete list, see [https://www.samba.org/~tpot/articles/firewall.html Samba port usage].
 +
 
 +
=== Usage ===
 +
 
 +
==== User Management ====
 +
 
 +
===== Adding a user =====
  
More information about the options available can be found in {{Codeline|man smb.conf}}
+
Samba requires a Linux user account - you may use an existing user account or create a [[Users and groups#User management|new one]].
  
===Starting and automating the daemons===
+
{{Note|The [[user]]/[[user group]] ''nobody'' should already exist on the system, it's used as the default {{ic|guest account}} and may be used for shares containing {{ic|1=guest ok = yes}}, thus preventing the need of user login on that share.}}
If using FAM, start the {{codeline|fam}} [[daemon]] before {{codeline|samba}}. Gamin does not need a daemon since it automatically starts when needed.
 
  
Without rebooting, FAM and Samba can be started with the commands:
+
Although the user name is shared with Linux system, Samba uses a password separate from that of the Linux user accounts. Replace {{ic|samba_user}} with the chosen Samba user account:
# rc.d start fam
 
# rc.d start samba
 
  
Add {{codeline|fam}} and {{codeline|samba}} to the DAEMONS line in {{Filename|[[rc.conf]]}} to automatically start the daemons at boot.
+
# smbpasswd -a ''samba_user''
  
Note: You do not need to use {{codeline|fam}} (fam usually fails in the startup). Just put the samba daemon in the rc.conf array.
+
Depending on the [https://www.samba.org/samba/docs/man/manpages-3/smb.conf.5.html#SERVERROLE server role], existing [[File permissions and attributes]] may need to be altered for the Samba user account.
  
===SWAT: Samba web administration tool===
+
If you want the new user only to be allowed to remotely access the file server shares through Samba, you can restrict other login options:
[http://samba.xsec.it/samba/docs/man/Samba-HOWTO-Collection/SWAT.html SWAT] is a facility that is part of the Samba suite. The main executable is called swat and is invoked by the eXtended InterNET Daemon, [[Wikipedia:xinetd|xinetd]].
 
  
There are many and varied opinions regarding the usefulness of SWAT. No matter how hard one tries to produce the perfect configuration tool, it remains an object of personal taste. SWAT is a tool that allows Web-based configuration of Samba. It has a wizard that may help to get Samba configured quickly, it has context-sensitive help on each {{Filename|smb.conf}} parameter, it provides for monitoring of current state of connection information, and it allows network-wide MS Windows network password management.[http://samba.xsec.it/samba/docs/man/Samba-HOWTO-Collection/SWAT.html]
+
* disabling shell - {{ic|usermod --shell /usr/bin/nologin --lock ''samba_user''}}
 +
* disabling SSH logons - edit {{ic|/etc/ssh/sshd_conf}}, change option {{ic|AllowUsers}}
  
{{Note|If you have problems with these directions, you can use the more all-encompasing [[Webmin]] tool instead, and easily load the SWAT module there.}}
+
Also see [[Security]] for hardening your system.
  
{{Warning|Before using SWAT, please be warned SWAT will completely replace your {{Filename|smb.conf}} with a fully optimized file that has been stripped of all comments you might have placed there, and only non-default settings will be written to the file.}}
+
===== Listing users =====
  
To use SWAT, first install xinetd:
+
Samba users can be listed using the {{man|8|pdbedit}} command:
# pacman -S xinetd
 
  
Edit {{Filename|/etc/xinetd.d/swat}} using your favorite text editor. To enable SWAT, change the {{Codeline|1=disable = yes}} line to {{Codeline|1=disable = no}}.
+
# pdbedit -L -v
  
service swat
+
===== Changing user password =====
{
 
        type                    = UNLISTED
 
        protocol                = tcp
 
        port                    = 901
 
        socket_type            = stream
 
        wait                    = no
 
        user                   = root
 
        server                  = /usr/sbin/swat
 
        log_on_success          += HOST DURATION
 
        log_on_failure          += HOST
 
        disable                = no
 
}
 
  
Alternatively you can add an entry for swat to {{Filename|/etc/services}} and omit the first 3 lines of the configuration.
+
To change a user password, use {{ic|smbpasswd}}:
  
Then start xinetd daemon:
+
# smbpasswd ''samba_user''
  
# rc.d start xinetd
+
==== Creating a share ====
  
The web interface can be accessed on port 901 by default:
+
{{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}}.}}
http://localhost:901/
 
  
===Adding users===
+
Make sure shares have been properly defined as per the ''Share Definitions'' section of [https://git.samba.org/samba.git/?p=samba.git;a=blob_plain;f=examples/smb.conf.default;hb=HEAD smb.conf.default].
To log into a Samba share you will need to add a user.
 
  
For Samba versions 3.4.0 and above:
+
==== Starting services ====
# pdbedit -a -u <user>
 
  
For earlier versions of Samba:
+
To provide basic file sharing through SMB [[start/enable]] {{ic|smb.service}} and/or {{ic|nmb.service}} services. See the {{man|8|smbd}} and {{man|8|nmbd}} man pages for details, as the {{ic|nmb.service}} service may not always be required.
# smbpasswd -a <user>
 
  
Existing smbpasswd databases can also be [[Samba#Changes_in_Samba_version_3.4.0|converted to the new format]].
+
{{Note|In {{Pkg|samba}} 4.8.0-1, the units were renamed from {{ic|smbd.service}} and {{ic|nmbd.service}} to {{ic|smb.service}} and {{ic|nmb.service}}.}}
  
The user must already have a account on the server. If the user does not exist you will receive the error:
+
=== Advanced Configuration ===
Failed to modify password entry for user "<user>"
 
  
You can add a new user to the Linux host with [[User Management#adduser|adduser]]. This article does not cover adding users to Windows systems.
+
==== Enable Usershares ====
  
{{Note|smbpasswd is no longer used by default as of [[Samba#Changes_in_Samba_version_3.4.0|Samba version 3.4.0]] }}
+
{{Note|This is an optional feature. Skip this section if you do not need it.}}
  
==Accessing shares==
+
[https://www.samba.org/samba/docs/current/man-html/smb.conf.5.html Usershares]
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.
+
is a feature that gives non-root users the capability to add, modify, and delete their own share definitions.  
  
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.
+
  # # create directory:
 +
# mkdir /var/lib/samba/usershares
 +
# # create group:
 +
# groupadd -r sambashare
 +
# # change the owner of the directory to 'root' and the group to 'sambashare':
 +
# chown root:sambashare /var/lib/samba/usershares
 +
  # # change the permissions of the 'usershares' directory so that users in the group 'sambashare' can read, write and execute files:
 +
# chmod 1770 /var/lib/samba/usershares
  
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.
+
Set the following parameters in the {{ic|smb.conf}} configuration file:
  
===Accessing a Samba share from Gnome/Xfce4===
+
{{hc|/etc/samba/smb.conf|2=
In order to access samba shares through Nautilus, first install the gvfs-smb and gnome-vfs packages:
+
[global]
  # pacman -S gvfs-smb gnome-vfs
+
  usershare path = /var/lib/samba/usershares
 +
  usershare max shares = 100
 +
  usershare allow guests = yes
 +
  usershare owner only = yes
 +
}}
 +
 
 +
Add the user to the ''sambashare'' group. Replace {{ic|''your_username''}} with the name of your user:
 +
 
 +
# gpasswd sambashare -a ''your_username''
 +
 
 +
[[Restart]] {{ic|smb.service}} and {{ic|nmb.service}} services.
 +
 
 +
Log out and log back in.
 +
 
 +
If you want to share paths inside your home directory you must make it accessible for the group ''others''.
 +
 
 +
In the GUI, for example in [[Thunar]], you can right click on any directory and share it on the network.
 +
 
 +
In the CLI, use one of the following commands, replacing italic ''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''
 +
 
 +
==== Set and forcing permissions ====
 +
 
 +
Permissions may be applied to both the server and shares:
 +
 
 +
{{hc|/etc/samba/smb.conf|2=
 +
[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
 +
}}
 +
 
 +
See {{man|5|smb.conf}} for a full overview of possible permission flags and settings.
 +
 
 +
==== Restrict protocols for better security ====
 +
 
 +
{{Warning|By default, Samba versions prior to 4.11 allow connections using the outdated and insecure SMB1 protocol. When using one these Samba versions, it is highly recommended to set {{ic|1=server min protocol = SMB2_02}} to protect yourself from ransomware attacks. In Samba 4.11 and newer, SMB2 is the default min protocol, so no changes are required there.}}
 +
 
 +
[[Append]] {{ic|server min protocol}} and {{ic|server max protocol}} in {{ic|/etc/samba/smb.conf}} to force usage of a minimum and maximum protocol:
 +
 
 +
{{hc|/etc/samba/smb.conf|2=
 +
[global]
 +
  server min protocol = SMB2_02
 +
  ; server max protocol = SMB3
 +
}}
 +
 
 +
See {{ic|server max protocol}} in {{man|5|smb.conf}} for an overview of supported protocols.
 +
 
 +
For compatibility with older clients and/or servers, you might need to set {{ic|1=client min protocol = CORE}} or {{ic|1=server min protocol = CORE}}, but please note that this makes you vulnerable to exploits in SMB1 including ransomware attacks.
 +
 
 +
{{Tip|Use {{ic|1=server min protocol = SMB3_00}} when clients should only connect using the latest SMB3 protocol, e.g. on clients running Windows 8 and later.}}
 +
 
 +
[[#Manual mounting|Clients]] using {{ic|mount.cifs}} may need to specify the correct {{ic|1=vers=*}}, e.g.:
 +
 
 +
# mount -t cifs //''SERVER''/''sharename'' /mnt/''mountpoint'' -o username=''username'',password=''password'',iocharset=''utf8'',vers=''3.1.1''
 +
 
 +
See {{man|8|mount.cifs}} for more information.
 +
 
 +
==== Use native SMB transport encryption ====
 +
 
 +
Native SMB transport encryption is available in SMB version 3.0 or newer. Clients supporting this type of encryption include Windows 8 and newer, Windows server 2012 and newer, and smbclient of Samba 4.1 and newer.
 +
 
 +
To use native SMB transport encryption by default, set the {{ic|smb encrypt}} parameter globally and/or by share. Possible values are {{ic|off}}, {{ic|enabled}} (default value), {{ic|desired}}, or {{ic|required}}:
 +
 
 +
{{hc|/etc/samba/smb.conf|2=
 +
[global]
 +
  smb encrypt = desired
 +
}}
 +
 
 +
See {{man|5|smb.conf}} for more information, especially the paragraphs ''Effects for SMB1'' and ''Effects for SMB2''.
 +
 
 +
{{Tip|When [[#Manual mounting|mounting]] a share, specify the {{ic|seal}} mount option to force usage of encryption.}}
 +
 
 +
==== Disable printer sharing ====
 +
 
 +
By default Samba shares printers configured using [[CUPS]].
 +
 
 +
If you do not want printers to be shared, use the following settings:
 +
 
 +
{{hc|/etc/samba/smb.conf|2=
 +
[global]
 +
  load printers = no
 +
  printing = bsd
 +
  printcap name = /dev/null
 +
  disable spoolss = yes
 +
  show add printer wizard = no
 +
}}
 +
 
 +
==== Block certain file extensions on Samba share ====
 +
 
 +
{{Note|Setting this parameter will affect the performance of Samba, as it will be forced to check all files and directories for a match as they are scanned.}}
 +
 
 +
Samba offers an option to block files with certain patterns, like file extensions. This option can be used to prevent dissemination of viruses or to dissuade users from wasting space with certain files. More information about this option can be found in {{man|5|smb.conf}}.
 +
 
 +
{{hc|/etc/samba/smb.conf|2=
 +
...
 +
[myshare]
 +
  comment = Private
 +
  path = /mnt/data
 +
  read only = no
 +
  veto files = /*.exe/*.com/*.dll/*.bat/*.vbs/*.tmp/*.mp3/*.avi/*.mp4/*.wmv/*.wma/
 +
}}
 +
 
 +
==== Improve throughput ====
 +
 
 +
{{Warning|Beware this may lead to corruption/connection issues and potentially cripple your TCP/IP stack.}}
 +
 
 +
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 {{man|5|smb.conf}} man page before applying any of the options listed below.
 +
 
 +
The following settings should be [[append]] to the {{ic|[global]}} section of {{ic|/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
 +
 
 +
{{Note|Network-interface adjustments may be needed for some options to work, see [[Sysctl#Networking]].}}
 +
 
 +
== Client ==
 +
 
 +
Install {{Pkg|smbclient}} for an {{ic|ftp}}-like command line interface. See {{man|1|smbclient}} for commonly used commands.
 +
 
 +
For a lightweight alternative (without support for listing public shares, etc.), [[install]] {{Pkg|cifs-utils}} that provides {{ic|/usr/bin/mount.cifs}}.
 +
 
 +
Depending on the [[desktop environment]], GUI methods may be available. See [[#File manager configuration]] for use with a file manager.
 +
 
 +
{{Note|
 +
* {{Pkg|smbclient}} requires a {{ic|/etc/samba/smb.conf}} file (see [[#Installation]]), which you can create as an empty file using the {{ic|touch}} utility.
 +
* After installing {{Pkg|cifs-utils}} or {{Pkg|smbclient}}, load the {{ic|cifs}} [[kernel module]] or reboot to prevent mount fails.
 +
}}
 +
 
 +
=== List public shares ===
 +
 
 +
The following command lists public shares on a server:
 +
 
 +
$ smbclient -L ''hostname'' -U%
 +
 
 +
Alternatively, running ''smbtree'' will show a tree diagram of all the shares. This is not advisable on a network with a lot of computers, but can be helpful for diagnosing if you have the correct sharename.
 +
 
 +
$ smbtree -b -N
 +
 
 +
Where the options are {{ic|-b}} ({{ic|--broadcast}}) to use broadcast instead of using the master browser and {{ic|-N}} ({{ic|-no-pass}}) to not ask for a password.
 +
 
 +
=== NetBIOS/WINS host names ===
 +
 
 +
You may need to [[start]] {{ic|winbind.service}} in order to resolve host names with e.g., {{ic|mount.cifs}}
 +
 
 +
If you are using apparmor and are unable to start winbind, you may need to add the below two lines to the apparmor profile for winbind:
 +
{{hc|/etc/apparmor.d/usr.sbin.winbindd|2=
 +
  ...
 +
  /var/cache/samba/msg.lock/* rwk,
 +
  /run/winbindd.pid rwk,
 +
  ...
 +
}
 +
}}
 +
 
 +
The {{pkg|smbclient}} package provides a driver to resolve host names using WINS. To enable it, add {{ic|wins}} to the “hosts” line in {{ic|/etc/nsswitch.conf}}.
 +
 
 +
If it is not already there, add it to look roughly like this:
 +
 
 +
{{hc|/etc/nsswitch.conf|2=
 +
...
 +
hosts: files mymachines myhostname mdns_minimal [NOTFOUND=return] resolve [!UNAVAIL=return] dns wins
 +
...
 +
}}
 +
 
 +
You can test WINS resolution with {{ic|nmblookup}}.  Note that WINS resolution requires incoming traffic originating from port 137.
 +
 
 +
==== Disable NetBIOS/WINS support ====
 +
 
 +
When not using NetBIOS/WINS host name resolution, it may be preferred to disable this protocol:
 +
 
 +
{{hc|/etc/samba/smb.conf|2=
 +
[global]
 +
  disable netbios = yes
 +
  dns proxy = no
 +
}}
 +
 
 +
Finally [[disable]]/[[stop]] {{ic|winbind.service}}.
 +
 
 +
=== Manual mounting ===
 +
 
 +
Create a mount point for the share:
 +
 
 +
# mkdir /mnt/''mountpoint''
 +
 
 +
Mount the share using {{ic|mount.cifs}} as {{ic|type}}. Not all the options listed below are needed or desirable:
 +
 
 +
  # mount -t cifs //''SERVER''/''sharename'' /mnt/''mountpoint'' -o username=''username'',password=''password'',workgroup=''workgroup'',iocharset=''utf8'',uid=''username'',gid=''group''
 +
 
 +
The options {{ic|uid}} and {{ic|gid}} corresponds to the local (e.g. client) [[user]]/[[user group]] to have read/write access on the given path.
 +
 
 +
{{Note|
 +
*If the {{ic|uid}} and {{ic|gid}} being used does not match the user of the server, the {{ic|forceuid}} and {{ic|forcegid}} options may be helpful. However note permissions assigned to a file when {{ic|forceuid}} or {{ic|forcegid}} are in effect may not reflect the the real (server) permissions. See the ''File And Directory Ownership And Permissions'' section in {{man|8|mount.cifs|FILE AND DIRECTORY OWNERSHIP AND PERMISSIONS}} for more information.
 +
*To allow users to mount it as long as the mount point resides in a directory controllable by the user; i.e. the user's home, append the {{ic|users}} mount option. The option is user'''s''' (plural). For other filesystem types handled by mount, this option is usually ''user''; sans the "'''s'''".
 +
*To mount a Windows share without authentification, use {{ic|1="username=*"}}.
 +
}}
 +
 
 +
{{Warning|Using {{ic|uid}} and/or {{ic|gid}} as mount options may cause I/O errors, it is recommended to set/check correct [[File permissions and attributes]] instead.}}
 +
 
 +
''SERVER''
 +
: The server name.
 +
 
 +
''sharename''
 +
: The shared directory.
 +
 
 +
''mountpoint''
 +
: The local directory where the share will be mounted.
 +
 
 +
{{ic|<nowiki>-o [options]</nowiki>}}
 +
: See {{man|8|mount.cifs}} for more information.
 +
 
 +
{{Note|
 +
* Abstain from using a trailing {{ic|/}}. {{ic|//''SERVER''/''sharename'''''/'''}} will not work.
 +
* If your mount does not work stable, stutters or freezes, try to enable different SMB protocol version with {{ic|1=vers=}} option. For example, {{ic|1=vers=2.0}} for Windows Vista mount.
 +
* If having timeouts on a mounted network share with cifs on a shutdown, see [[WPA supplicant#Problem with mounted network shares (cifs) and shutdown]].
 +
}}
  
For access under Xfce4 using thunar, one only needs gvfs-smb
+
==== Storing share passwords ====
# pacman -S gvfs-smb
 
  
From a Nautilus/Thunar window, hit {{Keypress|Ctrl}}+{{Keypress|L}} or go to the "Go" menu and select "Location..." -- both actions will allow for the typing in the "Go to:" blank.  Enter:
+
Storing passwords in a world readable file is not recommended. A safer method is to use a credentials file instead, e.g. inside {{ic|/etc/samba/credentials}}:
smb://servername/share
 
  
{{Note|If the servername is not in {{Filename|/etc/hosts}}, use the IP Address of the server in place of the servername.}}
+
{{hc|/etc/samba/credentials/share|2=
 +
username=''myuser''
 +
password=''mypass''
 +
}}
  
Another Gnome browser program is Gnomba.
+
Replace {{ic|1=username=myuser,password=mypass}} with {{ic|1=credentials=/etc/samba/credentials/share}}.
  
If iptables is running, the '''nf_conntrack_netbios_ns''' module should be loaded:
+
The credential file should explicitly readable/writeable to root:
modprobe nf_conntrack_netbios_ns
 
  
===Accessing shares from other graphical environments===
+
# chown root:root /etc/samba/credentials
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.
+
  # chmod 700 /etc/samba/credentials
 +
  # chmod 600 /etc/samba/credentials/share
  
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.
+
=== Automatic mounting ===
  
Other possible programs include pyneighborhood and RUmba, as well as the xffm-samba plugin for Xffm.
+
{{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.}}
  
===Accessing a Samba share from the shell===
+
==== As mount entry ====
Shares may be accessed by using an automatic mounter or by using a [[#Manual share mounting|manual method]].
 
  
====Automatic share mounting====
+
This is a simple example of a {{ic|cifs}} [[fstab|mount entry]] that requires authentication:
There are several alternatives for easy share browsing.
 
  
=====smbnetfs=====
+
{{hc|/etc/fstab|2=
1. Install {{Package Official|smbnetfs}}:
+
//''SERVER''/''sharename'' /mnt/''mountpoint'' cifs username=''myuser'',password=''mypass'' 0 0
# pacman -S smbnetfs
+
}}
  
2. Add the following line to {{Filename|/etc/fuse.conf}}:
+
{{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}}.}}
user_allow_other
 
  
3. Load the {{Codeline|fuse}} kernel module:
+
{{Tip|Use {{ic|x-systemd.automount}} if you want them to be mounted only upon access. See [[Fstab#Remote filesystem]] for details.}}
# modprobe fuse
 
  
4. Start the {{Codeline|smbnetfs}} [[daemon]]:
+
==== As systemd unit ====
# /etc/rc.d/smbnetfs start
 
  
If the required configuration is properly researched and done, it is claimed that all shares in the network are now automatically mounted under {{Filename|/mnt/smbnet}}.
+
Create a new {{ic|.mount}} file inside {{ic|/etc/systemd/system}}, e.g. {{ic|mnt-myshare.mount}}. See {{man|5|systemd.mount}} for details.
  
Add the following to {{Filename|/etc/rc.conf}} to access the shares at boot:
+
{{Note|Make sure the filename corresponds to the mountpoint you want to use.
MODULES=(... '''fuse''' ...)
+
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.}}.}}
DAEMONS=(... '''smbnetfs''' ...)
 
  
If a username and a password are required to access some of the shared folders, you have to edit {{filename|/etc/smbnetfs/.smb/smbnetfs.conf}} by uncommenting the line starting with "auth" and editing it to your needs:
+
{{ic|1=What=}} path to share
  
auth "hostname" "username" "password"
+
{{ic|1=Where=}} path to mount the share
  
Then, it may be necessary to change the permissions of {{filename|/etc/smbnetfs/.smb/smbnetfs.conf}} and all include files for smbnetfs to work correctly:
+
{{ic|1=Options=}} share mounting options
  
# chmod 600 /etc/smbnetfs/.smb/smbnetfs.conf
+
{{Note|
 +
* Network mount units automatically acquire {{ic|After}} dependencies on ''remote-fs-pre.target'', ''network.target'' and ''network-online.target'', and gain a {{ic|Before}} dependency on ''remote-fs.target'' unless {{ic|nofail}} mount option is set. Towards the latter a {{ic|Wants}} unit is added as well.
 +
* [[Append]] {{ic|noauto}} to {{ic|Options}} 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 {{ic|1=nss-lookup.target}} to {{ic|1=After}} and {{ic|1=Wants}}. This might avoid mount errors at boot time that do not arise when testing the unit.}}
  
=====fusesmb=====
+
{{hc|/etc/systemd/system/mnt-myshare.mount|2=
{{Note|1=Because {{Codeline|smbclient 3.2.X}} is malfunctioning with {{Codeline|fusesmb}}, revert to using older versions if necessary. See the [http://bbs.archlinux.org/viewtopic.php?id=58434 relevant forum topic] for details.}}
+
[Unit]
 +
Description=Mount Share at boot
  
1. Install the {{Package AUR|fusesmb}} package from the [[AUR]].
+
[Mount]
 +
What=//server/share
 +
Where=/mnt/myshare
 +
Options=x-systemd.automount,credentials=/etc/samba/credentials/myshare,iocharset=utf8,rw
 +
Type=cifs
 +
TimeoutSec=30
  
2. Create a mount point:
+
[Install]
# mkdir /mnt/fusesmb
+
WantedBy=multi-user.target
 +
}}
  
3. Load {{Codeline|fuse}} module:
+
{{Tip|In case of an unreachable system, [[append]] {{ic|1=ForceUnmount=true}} to {{ic|[Mount]}}, allowing the share to be (force-)unmounted.}}
# modprobe fuse
 
  
4. Mount the shares:
+
To use {{ic|mnt-myshare.mount}}, [[start]] the unit and [[enable]] it to run on system boot.
# fusesmb -o allow_other /mnt/fusesmb
 
  
For mounting shares at boot, add the command above to {{Filename|/etc/rc.local}} and add {{Codeline|fuse}} module to {{Filename|/etc/rc.conf}}:
+
==== smbnetfs ====
MODULES=(... '''fuse''' ...)
 
  
=====Autofs=====
+
{{Note|1=smbnetfs needs an intact Samba server setup.
See [[Autofs]] for information on the kernel-based automounter for Linux.
+
See above on how to do that.}}
  
====Manual share mounting====
+
First, check if you can see all the shares you are interested in mounting:
1. Use [[smbclient]] to browse shares from the shell. To list any public shares on a server:
+
  $ smbtree -U ''remote_user''
  $ smbclient -L <hostname> -U%
 
  
2. Create the mount point for the share:
+
If that does not work, find and modify the following line
# mkdir /mnt/MOUNTPOINT
+
in {{ic|/etc/samba/smb.conf}} accordingly:
  
3. Mount the share using {{Codeline|mount.cifs}}. Keep in mind that not all options may be needed nor desirable, such as {{Codeline|password}}:
+
  domain master = auto
  # mount -t cifs //''SERVER''/''SHARENAME'' ''MOUNTPOINT'' -o user=''USERNAME'',password=''PASSWORD'',workgroup=''WORKGROUP'',ip=''SERVERIP''
 
  
;{{Codeline|SERVER}}: The Windows system's name
+
Now [[restart]] {{ic|smb.service}} and {{ic|nmb.service}}.
;{{Codeline|SHARENAME}}: The shared directory
 
;{{Codeline|MOUNTPOINT}}: The local directory where the share will be mounted to
 
;{{Codeline|-o [options]}}: Specifies options for {{Codeline|mount.cifs}}
 
:;{{Codeline|user}}: Username used to mount the share
 
:;{{Codeline|password}}: The shared directory's password
 
:;{{Codeline|workgroup}}: Used to specify the workgroup
 
:;{{Codeline|ip}}: The IP address of the server -- if the system is unable to find the Windows computer by name (DNS, WINS, hosts entry, etc.)
 
  
{{Note|Abstain from using trailing directory ('''/''') characters. Using {{Filename|//SERVER/SHARENAME'''/'''}} will not work.}}
+
If everything works as expected, [[pacman#Installing specific packages|install]] {{Pkg|smbnetfs}} from the official repositories.
  
4. To unmount the share, use:
+
Then, add the following line to {{ic|/etc/fuse.conf}}:
# umount /mnt/MOUNTPOINT
 
  
=====Adding the share to {{Filename|fstab}}=====
+
  user_allow_other
Add the following to {{Filename|/etc/[[fstab]]}} for easy mounting:
 
  //SERVER/SHARENAME /mnt/MOUNTPOINT cifs noauto,noatime,username=USER,password=PASSWORD,workgroup=WORKGROUP,ip=SERVERIP 0 0
 
  
The {{Codeline|noauto}} option disables mounting it automatically at boot and {{Codeline|noatime}} increases performance by skipping inode access times.
+
Now copy the directory {{ic|/etc/smbnetfs/.smb}} to your home directory:
  
After adding the previous line, the syntax to mount files becomes simpler:
+
  $ cp -a /etc/smbnetfs/.smb ~
  # mount /mnt/MOUNTPOINT
 
  
If adding a Samba share to {{Filename|fstab}}, the {{codeline|netfs}} daemon should also be added to {{Filename|[[rc.conf]]}}, somewhere after the [[network]] daemon. The {{codeline|netfs}} daemon will mount network partitions at boot and, more importantly, unmount network partitions at shutdown. Even if using the {{codeline|noauto}} option in {{Filename|fstab}}, the {{codeline|netfs}} daemon should be used. Without it any network share that is mounted when shutting down will cause the {{codeline|network}} daemon to wait for the connection to time out, considerably extending poweroff time.
+
Then create a link to {{ic|smb.conf}}:
  
=====Allowing users to mount=====
+
$ ln -sf /etc/samba/smb.conf ~/.smb/smb.conf
Before enabling access to the mount commands, {{Filename|fstab}} needs to be modified. Add the {{Codeline|users}} options to the entry in {{Filename|/etc/fstab}}:
 
//SERVER/SHARENAME /path/to/SHAREMOUNT cifs '''users''',noauto,noatime,username=USER,password=PASSWORD,workgroup=WORKGROUP,ip=SERVERIP 0 0
 
  
{{Note|The option is {{codeline|user'''s'''}} (plural). For other filesystem types handled by mount, this option is usually  ''user''; sans the "'''s'''".}}
+
If a username and a password are required to access some of the shared folders, edit {{ic|~/.smb/smbnetfs.auth}}
 +
to include one or more entries like this:
  
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]].
+
{{hc|~/.smb/smbnetfs.auth|
 +
auth "hostname" "username" "password"
 +
}}
  
== Tips and tricks ==
+
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}}.
  
=== Share files for your LAN without user and password ===
+
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:
  
==== Option 1 - Force guest connections ====
+
{{hc|~/.smb/smbnetfs.conf|
 +
free_space_size 1073741824
 +
}}
  
Edit {{Filename|/etc/samba/smb.conf}} and change the following line:
+
When you are done with the configuration, you need to run
  
  security = user
+
  $ chmod 600 ~/.smb/smbnetfs.*
  
to
+
Otherwise, smbnetfs complains about 'insecure config file permissions'.
  
security = share
+
Finally, to mount your Samba network neighbourhood to a directory of your choice, call
  
==== Option 2 - Allow guest and User connections ====
+
$ smbnetfs ''mount_point''
  
Edit {{Filename|/etc/samba/smb.conf}} and add the following line:
+
===== Daemon =====
  
map to guest = Bad User
+
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 {{ic|/etc/smbnetfs/.smb}}.
  
After this line
+
Then, you can start and/or enable the {{ic|smbnetfs}} [[daemon]] as usual. The system-wide mount point is at {{ic|/mnt/smbnet/}}.
  
security = user
+
==== autofs ====
  
 +
See [[Autofs]] for information on the kernel-based automounter for Linux.
  
If you want to restrict the shares data to a specific interface replace:
+
=== File manager configuration ===
  
;  interfaces = 192.168.12.2/24 192.168.13.2/24
+
==== GNOME Files, Nemo, Caja, Thunar and PCManFM ====
  
with:
+
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]].
  
interfaces = lo eth0
+
Press {{ic|Ctrl+l}} and enter {{ic|smb://''servername''/''share''}} in the location bar to access your share.
bind interfaces only = true
 
  
(changing eth0 to the local network you want share with.)
+
The mounted share is likely to be present at {{ic|/run/user/''your_UID''/gvfs}} or {{ic|~/.gvfs}} in the filesystem.
  
If you want to edit the account that access the shares, edit the following line:
+
==== KDE ====
  
;  guest account = nobody
+
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.
  
The last step is to create share directory (for write access make writable = yes):
+
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].
  
[Public Share]
+
==== Other graphical environments ====
path = /path/to/public/share
 
available = yes
 
browsable = yes
 
public = yes
 
writable = no
 
  
=== Sample configuration file ===
+
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.
  
The configuration that worked for one user:
+
* {{Pkg|pyneighborhood}} is available in the official repositories.
[global]
+
* 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.
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
 
  
=== Adding network shares using KDE4 GUI ===
+
== Tips and tricks ==
How to configure the folder sharing in KDE4. Simple file sharing limits user shared folders to their home directory and read-only access. Advanced file sharing gives full semantics of Samba with no limits to shared folders but requires su or sudo root permissions.
 
* Read only, simple file sharing: [[Samba/Simple file sharing with KDE4]]
 
* Full capability file sharing: [[Samba/Advanced file sharing with KDE4]]
 
  
 
=== 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 {{Package Official|nmap}} and {{Package Official|smbclient}} using [[pacman]]:
+
1. First, [[install]] the {{Pkg|nmap}} and {{Pkg|smbclient}} packages.
# pacman -S nmap smbclient
 
  
2. {{Codeline|nmap}} checks which ports are open:
+
2. {{ic|nmap}} checks which ports are open:
  # nmap -p 139 -sT 192.168.1.*
+
 
 +
  # 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:
 
In this case, a scan on the 192.168.1.* IP address range and port 139 has been performed, resulting in:
{{Command
+
 
|name=nmap -sT 192.168.1.*
+
{{hc|$ nmap -sT "192.168.1.*"|
|output=Starting nmap 3.78 ( http://www.insecure.org/nmap/ ) at 2005-02-15 11:45 PHT
+
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 334: Line 586:
 
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 {{Codeline|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:  
{{Command
+
 
|name=nmblookup -A 192.168.1.1
+
{{hc|$ nmblookup -A 192.168.1.1|
|output=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 350: Line 602:
 
Regardless of the output, look for '''<20>''', which shows the host with open services.
 
Regardless of the output, look for '''<20>''', which shows the host with open services.
  
4. Use {{Codeline|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:
{{Command
+
 
|name=smbclient -L \\PUTER
+
{{hc|$ smbclient -L \\PUTER|2=
|output=<nowiki>
 
 
Sharename      Type      Comment
 
Sharename      Type      Comment
 
---------      ----      -------
 
---------      ----      -------
Line 369: Line 620:
 
---------            -------
 
---------            -------
 
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 cannot 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 391: Line 641:
  
 
== 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 {{Filename|/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/" rk,
 +
"/data/**" lrwk,
 +
}}
  
Note that you have to add this to your '''local''' smb.conf, not to the server's smb.conf
+
=== No dialect specified on mount ===
  
[global]
+
The client is using an unsupported SMB/CIFS version that is required by the server.
# lanman fix
 
client lanman auth = yes
 
client ntlmv2 auth = no
 
  
=== Getting a dialog box up takes a long time ===
+
See [[#Restrict protocols for better security]] for more information.
  
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:
+
=== Unable to overwrite files, permissions errors ===
  
[2009/11/11 06:20:12, 0] printing/print_cups.c:cups_connect(103)
+
{{Accuracy|An user should set/check for server/client permissions, instead of using incorrect/possible insecure flags.}}
Unable to connect to CUPS server localhost:631 - Interrupted system call
 
  
I do not have any printer connected to this server, so I added this to the global section:
+
Possible solutions:
  
  load printers = no
+
* Append the mount option {{ic|nodfs}} to the {{ic|/etc/fstab}} [[#As mount entry|entry]].
printing = bsd
+
* Add {{ic|1=msdfs root = no}} to the {{ic|[global]}} section of the server's {{ic|/etc/samba/smb.conf}}.
disable spoolss = yes
+
 
  printcap name = /dev/null
+
=== 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}}:
 +
 
 +
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:
 +
 
 +
* {{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}})
 +
 
 +
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.}}
 +
 
 +
[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
 +
}}
  
=== Changes in Samba version 3.4.0 ===
+
==== Verify folder access by guest ====
  
[http://www.samba.org/samba/history/samba-3.4.0.html Major enhancements in Samba 3.4.0] include:
+
Run the following command from a terminal. If prompted for a password, just press Enter:
  
The default passdb backend has been changed to 'tdbsam'! That breaks existing setups using the 'smbpasswd' backend without explicit declaration!
+
$ smbclient -L localhost
  
If you would like to stick to the 'smbpasswd' backend try changing this in {{Filename|/etc/samba/smb.conf}}:
+
If everything is fine, MySharedFiles should be displayed under {{ic|Sharename}} column
  
passdb backend = smbpasswd
+
Run the following command in order to access the shared folder as guest (anonymous login)
  
or convert your smbpasswd entries using:
+
$ smbclient -N //localhost/MySharedFiles
  
sudo pdbedit -i smbpasswd -e tdbsam
+
If everything is fine samba client prompt will be displayed:
  
 +
smb: \>
  
=== Error: Value too large for defined data type ===
+
From samba prompt verify guest can list directory contents:
  
With some applications you could get this error whith every attempt to open a file mounted in smbfs/cifs:
+
smb: \> ls
  
  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.
  
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):
+
Run the following commands as root to set correct permissions for folders:
  
  ,nounix,noserverino
+
# cd /home
 +
# chmod -R 755 /home/yourUser/Shared
  
''It works on Arch Linux up-to-date (2009-12-02)''
+
Access shared folder again as guest to be sure guest read access error has been solved.
  
=== I need to restart samba in order get my shares visible by other  ===
+
=== 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.
  
If upon starting your computer, the samba shares you have defined cannot be accessed from any client, check the following :
+
{{Note|SMB version 1 is known to have security vulnerabilities and was used in successful ransomware attacks.}}
* Make sure that you have not forgotten to add the samba daemon to the DAEMONS array of /etc/rc.conf (after the 'network' daemon)
+
 
* The ''network'' service is not started in the background (prefixed with @ ). Removing the '@' in front of 'network' can fix the issue. Reboot to check.
+
=== Software caused connection abort ===
 +
 
 +
File managers that utilizes {{Pkg|gvfs-smb}} can show the error {{ic|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 {{ic|1=vers=1.0}}. E.g.:
 +
 
 +
{{hc|/etc/fstab|2=
 +
//SERVER/sharename /mnt/mountpoint cifs guest,file_mode=0777,dir_mode=0777,vers=1.0 0 0
 +
}}
  
My guess on what has happened: When samba starts, the network is not properly initialized, so the server does not know on which interface to listen and thus fails to initialize correctly.
+
== 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 10:18, 1 September 2019

Samba is a re-implementation of the SMB networking protocol. It facilitates file and printer sharing among Linux and Windows systems as an alternative to NFS. This article provides instructions for users on how to setup Samba.

Contents

Server

Installation

Install the samba package.

Samba is configured in the /etc/samba/smb.conf configuration file, which is extensively documented in smb.conf(5).

Because the samba package does not provide this file, one needs to create it before starting smb.service.

A documented example as in smb.conf.default from the Samba git repository may be used to setup /etc/samba/smb.conf.

Note:
  • The default configuration sets log file to a non-writable location, which will cause errors - apply one of the following workarounds:
    • Change the log file location to a writable path: log file = /var/log/samba/%m.log
    • Change logging to a non-file backend solution: logging = syslog with syslog only = yes, or use logging = systemd
  • If required; the workgroup specified in the [global] section has to match the Windows workgroup (default WORKGROUP).
Tip: Whenever you modify the smb.conf file, run the testparm(1) command to check for syntactic errors.

Configure Firewall

If you are using a firewall, do not forget to open required ports (usually 137-139 + 445). For a complete list, see Samba port usage.

Usage

User Management

Adding a user

Samba requires a Linux user account - you may use an existing user account or create a new one.

Note: The user/user group nobody should already exist on the system, it's used as the default guest account and may be used for shares containing guest ok = yes, thus preventing the need of user login on that share.

Although the user name is shared with Linux system, Samba uses a password separate from that of the Linux user accounts. Replace samba_user with the chosen Samba user account:

# smbpasswd -a samba_user

Depending on the server role, existing File permissions and attributes may need to be altered for the Samba user account.

If you want the new user only to be allowed to remotely access the file server shares through Samba, you can restrict other login options:

  • disabling shell - usermod --shell /usr/bin/nologin --lock samba_user
  • disabling SSH logons - edit /etc/ssh/sshd_conf, change option AllowUsers

Also see Security for hardening your system.

Listing users

Samba users can be listed using the pdbedit(8) command:

# pdbedit -L -v
Changing user password

To change a user password, use smbpasswd:

# smbpasswd samba_user

Creating a share

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.

Make sure shares have been properly defined as per the Share Definitions section of smb.conf.default.

Starting services

To provide basic file sharing through SMB start/enable smb.service and/or nmb.service services. See the smbd(8) and nmbd(8) man pages for details, as the nmb.service service may not always be required.

Note: In samba 4.8.0-1, the units were renamed from smbd.service and nmbd.service to smb.service and nmb.service.

Advanced Configuration

Enable Usershares

Note: This is an optional feature. Skip this section if you do not need it.

Usershares is a feature that gives non-root users the capability to add, modify, and delete their own share definitions.

# # create directory:
# mkdir /var/lib/samba/usershares
# # create group:
# groupadd -r sambashare
# # change the owner of the directory to 'root' and the group to 'sambashare':
# chown root:sambashare /var/lib/samba/usershares
# # change the permissions of the 'usershares' directory so that users in the group 'sambashare' can read, write and execute files:
# chmod 1770 /var/lib/samba/usershares

Set the following parameters in the smb.conf configuration file:

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

Add the user to the sambashare group. Replace your_username with the name of your user:

# gpasswd sambashare -a your_username

Restart smb.service and nmb.service services.

Log out and log back in.

If you want to share paths inside your home directory you must make it accessible for the group others.

In the GUI, for example in Thunar, you can right click on any directory and share it on the network.

In the CLI, use one of the following commands, replacing italic 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

Set and forcing permissions

Permissions may be applied to both the server and shares:

/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

See smb.conf(5) for a full overview of possible permission flags and settings.

Restrict protocols for better security

Warning: By default, Samba versions prior to 4.11 allow connections using the outdated and insecure SMB1 protocol. When using one these Samba versions, it is highly recommended to set server min protocol = SMB2_02 to protect yourself from ransomware attacks. In Samba 4.11 and newer, SMB2 is the default min protocol, so no changes are required there.

Append server min protocol and server max protocol in /etc/samba/smb.conf to force usage of a minimum and maximum protocol:

/etc/samba/smb.conf
[global]
  server min protocol = SMB2_02
  ; server max protocol = SMB3

See server max protocol in smb.conf(5) for an overview of supported protocols.

For compatibility with older clients and/or servers, you might need to set client min protocol = CORE or server min protocol = CORE, but please note that this makes you vulnerable to exploits in SMB1 including ransomware attacks.

Tip: Use server min protocol = SMB3_00 when clients should only connect using the latest SMB3 protocol, e.g. on clients running Windows 8 and later.

Clients using mount.cifs may need to specify the correct vers=*, e.g.:

# mount -t cifs //SERVER/sharename /mnt/mountpoint -o username=username,password=password,iocharset=utf8,vers=3.1.1

See mount.cifs(8) for more information.

Use native SMB transport encryption

Native SMB transport encryption is available in SMB version 3.0 or newer. Clients supporting this type of encryption include Windows 8 and newer, Windows server 2012 and newer, and smbclient of Samba 4.1 and newer.

To use native SMB transport encryption by default, set the smb encrypt parameter globally and/or by share. Possible values are off, enabled (default value), desired, or required:

/etc/samba/smb.conf
[global]
  smb encrypt = desired

See smb.conf(5) for more information, especially the paragraphs Effects for SMB1 and Effects for SMB2.

Tip: When mounting a share, specify the seal mount option to force usage of encryption.

Disable printer sharing

By default Samba shares printers configured using CUPS.

If you do not want printers to be shared, use the following settings:

/etc/samba/smb.conf
[global]
  load printers = no
  printing = bsd
  printcap name = /dev/null
  disable spoolss = yes
  show add printer wizard = no

Block certain file extensions on Samba share

Note: Setting this parameter will affect the performance of Samba, as it will be forced to check all files and directories for a match as they are scanned.

Samba offers an option to block files with certain patterns, like file extensions. This option can be used to prevent dissemination of viruses or to dissuade users from wasting space with certain files. More information about this option can be found in 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

Warning: Beware this may lead to corruption/connection issues and potentially cripple your TCP/IP stack.

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
Note: Network-interface adjustments may be needed for some options to work, see Sysctl#Networking.

Client

Install smbclient for an ftp-like command line interface. See smbclient(1) for commonly used commands.

For a lightweight alternative (without support for listing public shares, etc.), install cifs-utils that provides /usr/bin/mount.cifs.

Depending on the desktop environment, GUI methods may be available. See #File manager configuration for use with a file manager.

Note:

List public shares

The following command lists public shares on a server:

$ smbclient -L hostname -U%

Alternatively, running smbtree will show a tree diagram of all the shares. This is not advisable on a network with a lot of computers, but can be helpful for diagnosing if you have the correct sharename.

$ smbtree -b -N

Where the options are -b (--broadcast) to use broadcast instead of using the master browser and -N (-no-pass) to not ask for a password.

NetBIOS/WINS host names

You may need to start winbind.service in order to resolve host names with e.g., mount.cifs

If you are using apparmor and are unable to start winbind, you may need to add the below two lines to the apparmor profile for winbind:

/etc/apparmor.d/usr.sbin.winbindd
...
  /var/cache/samba/msg.lock/* rwk, 
  /run/winbindd.pid rwk,
  ...
}

The smbclient package provides a driver to resolve host names using WINS. To enable it, add wins to the “hosts” line in /etc/nsswitch.conf.

If it is not already there, add it to look roughly like this:

/etc/nsswitch.conf
...
 hosts: files mymachines myhostname mdns_minimal [NOTFOUND=return] resolve [!UNAVAIL=return] dns wins
 ...

You can test WINS resolution with nmblookup. Note that WINS resolution requires incoming traffic originating from port 137.

Disable NetBIOS/WINS support

When not using NetBIOS/WINS host name resolution, it may be preferred to disable this protocol:

/etc/samba/smb.conf
[global]
  disable netbios = yes
  dns proxy = no

Finally disable/stop winbind.service.

Manual mounting

Create a mount point for the share:

# mkdir /mnt/mountpoint

Mount the share using mount.cifs as type. Not all the options listed below are needed or desirable:

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

The options uid and gid corresponds to the local (e.g. client) user/user group to have read/write access on the given path.

Note:
  • If the uid and gid being used does not match the user of the server, the forceuid and forcegid options may be helpful. However note permissions assigned to a file when forceuid or forcegid are in effect may not reflect the the real (server) permissions. See the File And Directory Ownership And Permissions section in mount.cifs(8) for more information.
  • To allow users to mount it as long as the mount point resides in a directory controllable by the user; i.e. the user's home, append the users mount option. The option is users (plural). For other filesystem types handled by mount, this option is usually user; sans the "s".
  • To mount a Windows share without authentification, use "username=*".
Warning: Using uid and/or gid as mount options may cause I/O errors, it is recommended to set/check correct File permissions and attributes instead.

SERVER

The server name.

sharename

The shared directory.

mountpoint

The local directory where the share will be mounted.

-o [options]

See mount.cifs(8) for more information.
Note:
  • Abstain from using a trailing /. //SERVER/sharename/ will not work.
  • If your mount does not work stable, stutters or freezes, try to enable different SMB protocol version with vers= option. For example, vers=2.0 for Windows Vista mount.
  • If having timeouts on a mounted network share with cifs on a shutdown, see WPA supplicant#Problem with mounted network shares (cifs) and shutdown.

Storing share passwords

Storing passwords in a world readable file is not recommended. A safer method is to use a credentials file instead, e.g. inside /etc/samba/credentials:

/etc/samba/credentials/share
username=myuser
password=mypass

Replace username=myuser,password=mypass with credentials=/etc/samba/credentials/share.

The credential file should explicitly readable/writeable to root:

# chown root:root /etc/samba/credentials
# chmod 700 /etc/samba/credentials
# chmod 600 /etc/samba/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. See systemd.mount(5) for details.

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..

What= path to share

Where= path to mount the share

Options= share mounting options

Note:
  • Network mount units automatically acquire After dependencies on remote-fs-pre.target, network.target and network-online.target, and gain a Before dependency on remote-fs.target unless nofail mount option is set. Towards the latter a Wants unit is added as well.
  • Append noauto to Options 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 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

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

[Install]
WantedBy=multi-user.target
Tip: In case of an unreachable system, append 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.

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 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.

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/" 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

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.

Note: SMB version 1 is known to have security vulnerabilities and was used in successful ransomware attacks.

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 guest,file_mode=0777,dir_mode=0777,vers=1.0 0 0

See also