Difference between revisions of "Samba"

From ArchWiki
Jump to: navigation, search
(Adding users)
(update interlanguage links)
(Tag: wiki-scripts)
 
(310 intermediate revisions by more than 100 users not shown)
Line 1: Line 1:
[[Category:Networking]]
+
[[Category:Network sharing]]
 
[[cs:Samba]]
 
[[cs:Samba]]
 +
[[da:Samba]]
 
[[de:Samba]]
 
[[de:Samba]]
[[da:Samba]]
 
 
[[es:Samba]]
 
[[es:Samba]]
 
[[fr:Samba]]
 
[[fr:Samba]]
 
[[it:Samba]]
 
[[it:Samba]]
 +
[[ja:Samba]]
 
[[ru:Samba]]
 
[[ru:Samba]]
 
[[sr:Samba]]
 
[[sr:Samba]]
[[tr:Samba]]
+
[[zh-hans:Samba]]
[[zh-CN:Samba]]
+
[[zh-hant:Samba]]
[[zh-TW:Samba]]
+
{{Related articles start}}
{{Article summary start|Summary}}
+
{{Related|Active Directory Integration}}
{{Article summary text|Installing, configuring and troubleshooting Samba}}
+
{{Related|Samba/Active Directory domain controller}}
{{Article summary heading|Related}}
+
{{Related|NFS}}
{{Article summary wiki|NFS}}
+
{{Related articles end}}
{{Article summary wiki|Samba Domain Controller}}
+
 
{{Article summary end}}
+
[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.
 +
 
 +
== Server configuration ==
  
'''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.
+
To share files with Samba, [[install]] the {{Pkg|samba}} package.
  
==Installation==
+
=== smb.conf ===
  
Installing only the {{Pkg|smbclient}}, available in the [[Official Repositories]], is sufficient for systems that are not meant to share files, only access them.
+
Samba is configured in {{ic|/etc/samba/smb.conf}}, if this file doesn't exist smbd will fail to start.
  
In order to make shares available to clients, install {{Pkg|samba}}, available in the [[Official Repositories]].
+
To get started you can copy the default config file from [https://git.samba.org/samba.git/?p=samba.git;a=blob_plain;f=examples/smb.conf.default;hb=HEAD samba git repository] to {{ic|/etc/samba/smb.conf}}.  
  
==Configuration==
+
{{Tip|The default configuration sets log file to a non-writable location, which will cause errors - it's better to change it to something arch-friendly: {{ic|log file <nowiki>=</nowiki> /var/log/samba/%m.log}}.}}
=== Basic Setup ===
 
The {{ic|/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.
 
  
As root, copy the default Samba configuration file to {{ic|/etc/samba/smb.conf}}:
+
The available options are documented in the {{man|5|smb.conf}} man page.
{{bc|# cp /etc/samba/smb.conf.default /etc/samba/smb.conf}}
+
Whenever you modify the file run the {{man|1|testparm}} command to check for syntactic errrors.
  
Edit {{ic|smb.conf}}. The default file creates a share for each user's home directory. It also creates a share for printers.
+
=== Creating a share ===
  
More information about the options available can be found in {{ic|man smb.conf}}. [http://www.samba.org/samba/docs/man/manpages-3/smb.conf.5.html Here] is the online version.
+
Open {{ic|/etc/samba/smb.conf}}, and scroll down to the '''Share Definitions''' section. The default configuration automatically creates a share for each user's home directory.  
  
To start Samba, start the '''smbd''' and '''nmbd''' [[daemon]]s or make them start automatically at boot.
+
The {{ic|workgroup}} specified in {{ic|smb.conf}} has to match the in use Windows workgroup (default {{ic|WORKGROUP}}).
  
{{Note|After starting the samba daemon check that files smbd.pid and nmbd.pid exist in /var/run/samba/ otherwise you will get an error. If not, simply create /var/run/samba directory and restart samba daemon.}}
+
=== Starting services ===
  
=== Shell Based Options ===
+
To provide basic file sharing through SMB [[start/enable]] {{ic|smbd.service}} and/or {{ic|nmbd.service}} services. See the {{man|8|smbd}} and {{man|8|nmbd}} man pages for details, as the {{ic|nmbd.service}} service may not always be required.
====Adding users====
 
To log into a Samba share, a samba user is needed.
 
# pdbedit -a -u <user>
 
  
The user must already have a [[Users and Groups|Linux user account]] on the server, if this is not the case, the following error will be displayed: {{ic|Failed to add entry for user <user>}}.
+
{{Tip|Instead of having the service running since boot, you can enable {{ic|smbd.socket}} so the daemon is started on the first incoming connection. Do not forget to disable {{ic|smbd.service}}.}}
  
{{Note|smbpasswd is no longer used by default as of Samba version 3.4.0 but existing smbpasswd databases can be [[Samba#Changes in Samba version 3.4.0|converted to the new format]]}}
+
=== Creating usershare path ===
 +
{{Note|This is an optional feature. Skip this section if you do not need it.}}
  
===Web Based Option ===
+
"Usershare" is a feature that gives non-root users the capability to add, modify, and delete their own share definitions.  
====SWAT: The Samba Web Administration Tool====
 
SWAT is a facility that is part of the Samba suite.
 
  
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 {{ic|smb.conf}} parameter, it provides for monitoring of current state of connection information, and it allows network-wide MS Windows network password management.
+
This creates the usershare directory in {{ic|/var/lib/samba}}:
  
{{Note|An all-encompasing [[Webmin]] tool instead can also be used, and easily load the SWAT module there.}}
+
# mkdir -p /var/lib/samba/usershare
  
{{Warning|Before using SWAT, be warned that SWAT will completely replace {{ic|smb.conf}} with a fully optimized file that has been stripped of all comments , and only non-default settings will be written to the file.}}
+
This creates the group sambashare:
  
To use SWAT, first install {{Pkg|xinetd}}, available in the [[Official Repositories]].
+
# groupadd -r sambashare
  
Edit {{ic|/etc/xinetd.d/swat}}. To enable SWAT, change the {{ic|1=disable = yes}} line to {{ic|1=disable = no}}.
+
This changes the owner of the directory to root and the group to sambashare:
  
{{bc|<nowiki>
+
# chown root:sambashare /var/lib/samba/usershare
service swat
+
 
{
+
This changes the permissions of the usershare directory so that users in the group sambashare can read, write and execute files:
        type                    = UNLISTED
+
 
        protocol                = tcp
+
# chmod 1770 /var/lib/samba/usershare
        port                    = 901
+
 
        socket_type            = stream
+
Set the following parameters in the {{ic|smb.conf}} configuration file:
        wait                    = no
+
 
        user                    = root
+
{{hc|/etc/samba/smb.conf|2=
        server                  = /usr/sbin/swat
+
...
        log_on_success          += HOST DURATION
+
[global]
        log_on_failure          += HOST
+
  usershare path = /var/lib/samba/usershare
        disable                = no
+
  usershare max shares = 100
}
+
  usershare allow guests = yes
</nowiki>
+
  usershare owner only = yes
 +
  ...
 
}}
 
}}
  
Alternatively, add an entry for swat to {{ic|/etc/services}} and omit the first 3 lines of the configuration.
+
Add your user to the ''sambashare'' group. Replace {{ic|''your_username''}} with the name of your user:
 +
 
 +
# gpasswd sambashare -a ''your_username''
 +
 
 +
Restart {{ic|smbd.service}} and {{ic|nmbd.service}} services.
 +
 
 +
Log out and log back in. You should now be able to configure your samba share using GUI. For example, in [[Thunar]] you can right click on any directory and share it on the network. If you want to share paths inside your home directory you must make it listable for the group others.
 +
 
 +
=== Adding a user ===
 +
 
 +
Samba requires a Linux user account - you may use an existing user account or create a [[Users and groups#User management|new one]].
 +
 
 +
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:
 +
 
 +
# smbpasswd -a ''samba_user''
 +
 
 +
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.
 +
 
 +
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 - {{ic|# usermod --shell /usr/bin/nologin --lock username}}
 +
* disabling SSH logons - edit {{ic|/etc/ssh/sshd_conf}}, change option {{ic|AllowUsers}}
 +
 
 +
Also see [[Security]] for hardening your system.
 +
 
 +
=== Listing users ===
  
Then start xinetd [[daemon]].
+
Samba users can be listed using the {{man|8|pdbedit}} command:
  
The web interface can be accessed on port 901 by default:
+
# pdbedit -L -v
{{ic|http://localhost:901/}}
 
  
==Accessing shares==
+
=== Changing Samba user's password ===
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.
 
  
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.
+
To change a user's password, use {{ic|smbpasswd}}:
  
If using KDE, it has the ability to browse Samba shares. Therefore do not need any additional packages.  (However, for a GUI in the KDE System Settings, install the kdenetwork-filesharing package from [extra].  Another program choice is SMB4K.)  If, however, users wish to use the share in Gnome or solely from a shell, an additional package is needed.
+
  # smbpasswd ''samba_user''
  
===Accessing a Samba share from GNOME/Xfce4/LXDE===
+
=== Required ports ===
In order to access samba shares through Nautilus, first install the {{Pkg|gvfs-smb}} and {{Pkg|gnome-vfs}} packages, available in the [[Official Repositories]].
 
  
For access under Xfce4 using Thunar or LXDE using pcmanfm, one only needs {{pkg|gvfs-smb}}, available in the [[Official Repositories]].
+
If you are using a [[firewall]], do not forget to open required ports (usually 137-139 + 445). For a complete list please check [https://wiki.samba.org/index.php/Samba_port_usage Samba port usage].
  
From a Nautilus/Thunar window, hit {{Keypress|Ctrl+L}} or go to the "Go" menu and select "Location..." -- both actions will allow for the typing in the "Go to:" blank.  Enter:
+
== Client configuration ==
{{ic|smb://servername/share}}
 
  
{{Note|If the servername is not in {{ic|/etc/hosts}}, use the IP address of the server in place of the servername.}}
+
For a lightweight method (without support for listing public shares, etc.), only install {{Pkg|cifs-utils}} to provide {{ic|/usr/bin/mount.cifs}}.
  
From a Pcmanfm window, under the "Go" menu choose "Network Files".
+
Install {{Pkg|smbclient}} for an ftp-like command line interface. See {{man|1|smbclient}} for commonly used commands.
  
Another GNOME browser program is Gnomba.
+
{{Note|{{Pkg|smbclient}} requires an /etc/samba/smb.conf file which the utility, touch, can generate (as an empty file), or if {{Pkg|samba}} is installed, it can be copied from the default [[#smb.conf]].}}
  
If iptables is running, the '''nf_conntrack_netbios_ns''' module should be loaded:
+
Depending on the [[desktop environment]], GUI methods may be available. See [[#File manager configuration]] for use with a file manager.
modprobe nf_conntrack_netbios_ns
 
  
===Accessing shares from other graphical environments===
+
{{Note|After installing {{Pkg|cifs-utils}} or {{Pkg|smbclient}}, load the {{ic|cifs}} [[kernel module]] or reboot to prevent mount fails.}}
There are a number of useful programs, but they will need to have packages created for them.  This can be done with the Arch package build system.  The good thing about these others is that they do not require a particular environment to be installed to support them, and so they bring along less baggage.
 
  
LinNeighborhood is non-specific when it comes to the DE or WM.  It can be seen as a simple and generic X-based LAN browser and share mounter.  Not pretty, but effective.
+
=== List Public Shares ===
 +
The following command lists public shares on a server:
  
Other possible programs include pyneighborhood and RUmba, as well as the xffm-samba plugin for Xffm.
+
$ smbclient -L ''hostname'' -U%
  
===Accessing a Samba share from the shell===
+
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.
Shares may be accessed by using an automatic mounter or by using a [[#Manual share mounting|manual method]].
 
  
====Automatic share mounting====
+
$ smbtree -b -N
There are several alternatives for easy share browsing.
 
  
=====smbnetfs=====
+
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.
Install {{Pkg|smbnetfs}}, available in the [[Official Repositories]].
 
Add the following line to {{ic|/etc/fuse.conf}}: {{bc|user_allow_other}}
 
Load the {{ic|fuse}} [[kernel module]] by issuing as root:
 
modprobe fuse
 
Start the {{ic|smbnetfs}} [[daemon]] by issuing as root:
 
systemctl start smbnetfs
 
  
If the required configuration is properly researched and done, it is claimed that all shares in the network are now automatically mounted under {{ic|/mnt/smbnet}}.
+
=== NetBIOS/WINS host names ===
  
To access the shares at boot:
+
You may need to [[start/enable]] winbindd in order to resolve host names with e.g., mount.cifs
systemctl enable smbnetfs
 
  
If a username and a password are required to access some of the shared folders, edit {{ic|/etc/smbnetfs/.smb/smbnetfs.conf}} and uncomment the line starting with "auth":
+
The {{pkg|smbclient}} package provides a driver to resolve host names using WINS. To enable it, add “wins” to the “hosts” line in /etc/nsswitch.conf.
  
auth "hostname" "username" "password"
+
=== Manual mounting ===
  
Then, it may be necessary to change the permissions of {{ic|/etc/smbnetfs/.smb/smbnetfs.conf}} and all include files for smbnetfs to work correctly:
+
Create a mount point for the share:
  
  # chmod 600 /etc/smbnetfs/.smb/smbnetfs.conf
+
  # mkdir /mnt/''mountpoint''
  
=====fusesmb=====
+
Mount the share using {{ic|mount.cifs}} as {{ic|type}}. Not all the options listed below are needed or desirable:
{{Note|1=Because {{ic|smbclient 3.2.X}} is malfunctioning with {{ic|fusesmb}}, revert to using older versions if necessary. See the [https://bbs.archlinux.org/viewtopic.php?id=58434 relevant forum topic] for details.}}
+
{{bc|1=
 +
# mount -t cifs //''SERVER''/''sharename'' /mnt/''mountpoint'' -o user=''username'',password=''password'',uid=''username'',gid=''group'',workgroup=''workgroup'',ip=''serverip'',iocharset=''utf8''
 +
}}
  
# Install {{AUR|fusesmb}}, available in the [[Arch User Repository]].
+
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.
# Create a mount point: {{ic|# mkdir /mnt/fusesmb}}
 
# Load {{ic|fuse}} [[kernel module]].
 
# Mount the shares: {{bc|# fusesmb -o allow_other /mnt/fusesmb}}
 
  
=====Autofs=====
+
{{Note|The option is user'''s''' (plural). For other filesystem types handled by mount, this option is usually ''user''; sans the "'''s'''".}}
See [[Autofs]] for information on the kernel-based automounter for Linux.
+
{{Warning|Using {{ic|uid}} and/or {{ic|gid}} as mount options may cause I/O errors, it's recommended to set/check the [[File permissions and attributes]] instead.}}
  
====Manual share mounting====
+
''SERVER''
1. Use [[smbclient]] to browse shares from the shell. To list any public shares on a server:
+
: The server name.
$ smbclient -L <hostname> -U%
 
  
2. Create the mount point for the share:
+
''sharename''
# mkdir /mnt/MOUNTPOINT
+
: The shared directory.
  
3. Mount the share using {{ic|mount.cifs}}. Keep in mind that not all options may be needed nor desirable, such as {{ic|password}}:
+
''mountpoint''
# mount -t cifs //''SERVER''/''SHARENAME'' ''/mnt''/''MOUNTPOINT'' -o user=''USERNAME'',password=''PASSWORD'',workgroup=''WORKGROUP'',ip=''SERVERIP''
+
: The local directory where the share will be mounted.
  
;{{ic|SERVER}}: The Windows system's name
+
{{ic|<nowiki>-o [options]</nowiki>}}
;{{ic|SHARENAME}}: The shared directory
+
: See {{man|8|mount.cifs}} for more information.
;{{ic|MOUNTPOINT}}: The local directory where the share will be mounted to
 
;{{ic|-o [options]}}: Specifies options for {{ic|mount.cifs}}
 
:;{{ic|user}}: Username used to mount the share
 
:;{{ic|password}}: The shared directory's password
 
:;{{ic|workgroup}}: Used to specify the workgroup
 
:;{{ic|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 {{ic|//SERVER/SHARENAME'''/'''}} will not work.}}
+
{{Note|
As CIFS refuses to mount [http://jmatrix.net/dao/case/case.jsp?case=7F000001-1766806-11E30195CFB-2593 unsecured samba share], the ''sec=none'' option needs to be used (and the user and password from the options list need to be removed).
+
* 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]].
 +
}}
  
If the mount command cannot resolve the server’s address but ''smbclient'' can, adding {{ic|wins}} to the {{ic|hosts}} line in {{ic|/etc/nsswitch.conf}} may help. The corresponding {{ic|/lib/libnss_wins.so}} driver must also be present, which is provided by the {{pkg|samba}} (server) package.
+
===== Storing Share Passwords =====
 +
Storing passwords in a world readable file is not recommended. A safer method is to create a credentials file:
 +
{{hc|/path/to/credentials/share|2=
 +
username=''myuser''
 +
password=''mypass''
 +
}}
 +
Replace {{ic|<nowiki>username=myuser,password=mypass</nowiki>}} with {{ic|<nowiki>credentials=/path/to/credentials/share</nowiki>}}.
  
4. To unmount the share, use:
+
The credential file should explicitly readable/writeable to root:
  # umount /mnt/MOUNTPOINT
+
  # chmod 600 /path/to/credentials/share
  
=====Adding the share to {{ic|fstab}}=====
+
=== Automatic mounting ===
Add the following to {{ic|/etc/[[fstab]]}} for easy mounting:
+
{{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.}}
//SERVER/SHARENAME /mnt/MOUNTPOINT cifs noauto,username=USER,password=PASSWORD,workgroup=WORKGROUP,ip=SERVERIP 0 0
 
  
The {{ic|noauto}} option disables mounting it automatically at boot and
+
==== As mount entry ====
  
After adding the previous line, the syntax to mount files becomes simpler:
+
This is an simple example of a {{ic|cifs}} [[fstab|mount entry]] that requires authentication:
# mount /mnt/MOUNTPOINT
+
{{hc|/etc/fstab|2=
 +
//''SERVER''/''sharename'' /mnt/''mountpoint'' cifs username=''myuser'',password=''mypass'' 0 0
 +
}}
  
Another option, to keep passwords out of sight, is to use the 'credentials' option:
+
{{Note|Space 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}}.}}
//SERVER/SHARENAME /path/to/SHAREMOUNT cifs noauto,credentials=/path/to/smbcredentials 0 0
 
  
The credentials file should contain the following text:
+
To speed up the service on boot, add the {{ic|1=x-systemd.automount}} option to the entry:
username=USERNAME
+
{{hc|/etc/fstab|2=
password=PASSWORD
+
//''SERVER''/''SHARENAME'' /mnt/''mountpoint'' cifs credentials=''/path/to/smbcredentials/share'',x-systemd.automount 0 0
 +
}}
  
It is highly recommended to <tt>chmod 600</tt> this file so that only the owning user can read and write to it.
+
==== As systemd unit ====
 +
Create a new {{ic|.mount}} file inside {{ic|/etc/systemd/system}}, e.g. {{ic|mnt-myshare.mount}}.
 +
{{Note|Make sure the filename corresponds to the mountpoint you want to use.
 +
E.g. the unit name {{ic|mnt-myshare.mount}} can only be used if are going to mount the share under {{ic|/mnt/myshare}}. Otherwise the following error might occur:
 +
"''systemd[1]: mnt-myshare.mount: {{ic|1=Where=}} setting doesn't match unit name. Refusing.''"
 +
}}
  
If adding a Samba share to {{ic|fstab}}, the {{ic|netfs}} daemon should also be added to {{ic|[[rc.conf]]}}, somewhere after the [[network]] daemon. The {{ic|netfs}} daemon will mount network partitions at boot and, more importantly, unmount network partitions at shutdown. Even if using the {{ic|noauto}} option in {{ic|fstab}}, the {{ic|netfs}} daemon should be used. Without it any network share that is mounted when shutting down will cause the {{ic|network}} daemon to wait for the connection to time out, considerably extending poweroff time.
+
{{ic|1=Requires=}} replace (if needed) with your [[:Category:Network_configuration|Network configuration]].
  
If using '''systemd''' (modern installations), one can utilize the '''comment=systemd.automount''' option, which speeds up service boot by a few seconds. Also, one can map current user and group to make life a bit easier, utilizing '''uid''' and '''gid''' options:
+
{{ic|1=What=}} path to share
//SERVER/SHARENAME /path/to/SHAREMOUNT cifs credentials=/path/to/smbcredentials,'''comment=systemd.automount''','''uid=USERNAME,gid=USERGROUP''' 0 0
 
  
=====Allowing users to mount=====
+
{{ic|1=Where=}} path to mount the share
Before enabling access to the mount commands, {{ic|fstab}} needs to be modified. Add the {{ic|users}} options to the entry in {{ic|/etc/fstab}}:
 
//SERVER/SHARENAME /path/to/SHAREMOUNT cifs '''users''',noauto,username=USER,password=PASSWORD,workgroup=WORKGROUP,ip=SERVERIP 0 0
 
  
{{Note|The option is {{ic|user'''s'''}} (plural). For other filesystem types handled by mount, this option is usually  ''user''; sans the "'''s'''".}}
+
{{ic|1=Options=}} share mounting options
  
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]].
+
{{Note|If you want to use a hostname for the server you want to share (instead of an IP address), add {{ic|1=systemd-resolved.service}} to {{ic|1=After}} and {{ic|1=Wants}}. This might avoid mount errors at boot time that don't arise when testing the unit.}}
  
== Tips and tricks ==
+
{{hc|/etc/systemd/system/mnt-myshare.mount|<nowiki>
 +
[Unit]
 +
Description=Mount Share at boot
 +
Requires=systemd-networkd.service
 +
After=network-online.target
 +
Wants=network-online.target
 +
 
 +
[Mount]
 +
What=//server/share
 +
Where=/mnt/myshare
 +
Options=credentials=/etc/samba/creds/myshare,iocharset=utf8,rw,x-systemd.automount
 +
Type=cifs
 +
TimeoutSec=30
 +
 
 +
[Install]
 +
WantedBy=multi-user.target
 +
</nowiki>}}
 +
 
 +
To use {{ic|mnt-myshare.mount}}, [[start]] the unit and [[enable]] it to run on system boot.
 +
 
 +
==== smbnetfs ====
 +
 
 +
{{Note|1=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''
  
=== Sample configuration file ===
+
If that does not work, find and modify the following line
 +
in {{ic|/etc/samba/smb.conf}} accordingly:
  
The following simple configuration file allows for a quick and easy setup to share any number of directories, as well as easy browsing from Windows clients.
+
domain master = auto
  
See [http://www.samba.org/samba/docs/man/manpages-3/smb.conf.5.html smb.conf] for details and explanation of configuration options.
+
Now [[restart]] {{ic|smbd.service}} and {{ic|nmbd.service}}.
  
<nowiki>
+
If everything works as expected, [[pacman#Installing specific packages|install]] {{Pkg|smbnetfs}} from the official repositories.
[global]
 
    workgroup = WORKGROUP
 
    server string = Samba Server
 
    netbios name = SERVER
 
    name resolve order = bcast host
 
    dns proxy = no
 
  
    log file = /var/log/samba/%m.log
+
Then, add the following line to {{ic|/etc/fuse.conf}}:
  
    create mask = 0664
+
user_allow_other
    directory mask = 0775
 
  
    force create mode = 0664
+
Now copy the directory {{ic|/etc/smbnetfs/.smb}} to your home directory:
    force directory mode = 0775
 
  
    ; One may be interested in the following setting:
+
$ cp -a /etc/smbnetfs/.smb ~
    ;force group = +nas
 
  
[media1]
+
Then create a link to {{ic|smb.conf}}:
    path = /media/media1
 
    read only = No
 
  
[media2]
+
$ ln -sf /etc/samba/smb.conf ~/.smb/smb.conf
    path = /media/media2
 
    read only = No
 
  
[media3]
+
If a username and a password are required to access some of the shared folders, edit {{ic|~/.smb/smbnetfs.auth}}
    path = /media/media3
+
to include one or more entries like this:
    read only = No
 
</nowiki>
 
  
Remember to <code>testparm -s</code> and <code>systemctl restart smbd nmbd</code> after editing configuration files.
+
{{hc|~/.smb/smbnetfs.auth|
 +
auth "hostname" "username" "password"
 +
}}
  
=== Share files without a username and password ===
+
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}}.
  
 +
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:
 +
{{hc|~/.smb/smbnetfs.conf|
 +
free_space_size 1073741824
 +
}}
  
Edit {{ic|/etc/samba/smb.conf}} and add the following line:
+
When you are done with the configuration, you need to run
 +
$ chmod 600 ~/.smb/smbnetfs.*
 +
Otherwise, smbnetfs complains about 'insecure config file permissions'.
  
  map to guest = Bad User
+
Finally, to mount your Samba network neighbourhood to a directory of your choice, call
 +
  $ smbnetfs ''mount_point''
  
After this line
+
===== Daemon =====
  
security = 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 directoy {{ic|/etc/smbnetfs/.smb}}.
  
Restrict the shares data to a specific interface replace:
+
Then, you can start and/or enable the {{ic|smbnetfs}} [[daemon]] as usual. The system-wide mount point is at {{ic|/mnt/smbnet/}}.
  
;  interfaces = 192.168.12.2/24 192.168.13.2/24
+
==== autofs ====
  
with:
+
See [[Autofs]] for information on the kernel-based automounter for Linux.
  
interfaces = lo eth0
+
=== File manager configuration ===
bind interfaces only = true
 
  
Optionally edit the account that access the shares, edit the following line:
+
==== GNOME Files, Nemo, Caja, Thunar and PCManFM ====
  
;  guest account = nobody
+
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]].
  
For example:
+
Press {{ic|Ctrl+l}} and enter {{ic|smb://''servername''/''share''}} in the location bar to access your share.
  
;  guest account = pcguest
+
The mounted share is likely to be present at {{ic|/run/user/''your_UID''/gvfs}} or {{ic|~/.gvfs}} in the filesystem.
  
And do something in the likes of:
+
==== KDE ====
  
# useradd -c "Guest User" -d /dev/null -s /bin/false pcguest
+
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 from the official repositories.
  
Then setup a "" password for user pcguest.
+
If you get a "Time Out" Error when navigating with Dolphin, you should uncomment and edit the following line in smb.conf:{{bc|1=name resolve order = lmhosts bcast host wins}}
 +
as shown in this [http://ubuntuforums.org/showthread.php?t=1605499 page].
  
The last step is to create share directory (for write access make writable = yes):
+
==== Other graphical environments ====
  
[Public Share]
+
There are a number of useful programs, but they may need to have packages created for them. This can be done with the Arch package build system. The good thing about these others is that they do not require a particular environment to be installed to support them, and so they bring along less baggage.
path = /path/to/public/share
 
available = yes
 
browsable = yes
 
public = yes
 
writable = no
 
  
=== Samba Security ===
+
* {{Pkg|pyneighborhood}} is available in the official repositories.
An extra layer of security can be obtainded by restricting your acceptable networks in the /etc/samba/smb.conf file:
+
* 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.
  
hosts deny = 0.0.0.0/0
+
== Tips and tricks ==
hosts allow = xxx.xxx.xxx.xxx/xx yyy.yyy.yyy.yyy/yy
 
  
If you're behind a firewall, make sure to open the ports Samba uses:
+
=== Improve performance ===
  
UDP/137 - used by nmbd
+
{{Expansion|Add explanations.}}
UDP/138 - used by nmbd
 
TCP/139 - used by smbd
 
TCP/445 - used by smbd
 
  
So a series of commands like this should suffice:
+
{{hc|/etc/samba/smb.conf|2=
 +
[global]
 +
        server multi channel support = yes
 +
        socket options = IPTOS_THROUGHPUT SO_KEEPALIVE
 +
        deadtime = 30
 +
        use sendfile = Yes
 +
        write cache size = 262144
 +
        min receivefile size = 16384
 +
        aio read size = 16384
 +
        aio write size = 16384
 +
        nt pipe support = no
 +
}}
  
# iptables -A INPUT -p tcp --dport 139 -j ACCEPT
+
{{Warning|1=nt pipe support = no breaks some windows functionality.}}
# iptables -A INPUT -p tcp --dport 445 -j ACCEPT
 
# iptables -A INPUT -p udp --sport 137 -j ACCEPT
 
# iptables -A INPUT -p udp --dport 137 -j ACCEPT
 
# iptables -A INPUT -p udp --dport 138 -j ACCEPT
 
  
If you're basing your firewall upon Arch Linux's [[Simple Stateful Firewall]], just substitute the INPUT chain for the correspondent TCP and UDP chains.
+
=== Disable printer share ===
 +
If you do not have printers to be shared, use the following setting to save some resources:
 +
{{hc|/etc/samba/smb.conf|2=
 +
[global]
 +
        load printers = No
 +
        printcap name = /dev/null
 +
        disable spoolss = Yes
 +
}}
  
=== Adding network shares using KDE4 GUI ===
+
=== Block certain file extensions on Samba share ===
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.
+
{{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.}}
* Read only, simple file sharing: [[Samba/Simple file sharing with KDE4]]
+
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}}.
* Full capability file sharing: [[Samba/Advanced file sharing with KDE4]]
+
 
 +
{{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/
 +
}}
  
 
=== Discovering network shares ===
 
=== Discovering network 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.
  
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 {{Pkg|nmap}} and {{Pkg|smbclient}} packages.
 
 
1. First, install {{Pkg|nmap}} and {{Pkg|smbclient}} using [[pacman]]:
 
# pacman -S nmap smbclient
 
  
 
2. {{ic|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:
 
{{hc
 
{{hc
|$ nmap -sT 192.168.1.*
+
|$ nmap -sT "192.168.1.*"
 
|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:
Line 358: Line 404:
 
The first result is another system; the second happens to be the client from where this scan was performed.
 
The first result is another system; the second happens to be the client from where this scan was performed.
  
3. Now that systems with port 139 open are revealed, use {{ic|nmblookup}} to check for NetBIOS names:  
+
3. Now that systems with port 139 open are revealed, use {{man|1|nmblookup}} to check for NetBIOS names:  
 
{{hc
 
{{hc
 
|$ nmblookup -A 192.168.1.1
 
|$ nmblookup -A 192.168.1.1
Line 394: Line 440:
 
HOMENET              PUTER
 
HOMENET              PUTER
 
</nowiki>}}
 
</nowiki>}}
 
This shows which folders are shared and can be mounted locally. See: [[#Accessing 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 if access to a Windows computer through remote desktop is not an option, 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.
  
Line 414: Line 457:
 
  $ net rpc
 
  $ net rpc
  
=== Block certain file extensions on samba share ===
+
===Share files without a username and password===
 +
Edit {{ic|/etc/samba/smb.conf}} and add the following line:
 +
{{bc|<nowiki>map to guest = Bad User</nowiki>}}
 +
 
 +
After this line:
 +
{{bc|<nowiki>security = user</nowiki>}}
 +
 
 +
Restrict the shares data to a specific interface replace:
 +
{{bc|<nowiki>;  interfaces = 192.168.12.2/24 192.168.13.2/24</nowiki>}}
 +
 
 +
with:
 +
 
 +
{{bc|<nowiki>
 +
interfaces = lo eth0
 +
bind interfaces only = true</nowiki>}}
 +
 
 +
Optionally edit the account that access the shares, edit the following line:
 +
{{bc|<nowiki>;  guest account = nobody</nowiki>}}
 +
 
 +
For example:
 +
{{bc|<nowiki>  guest account = pcguest</nowiki>}}
 +
 
 +
And do something in the likes of:
 +
{{bc|<nowiki># useradd -c "Guest User" -d /dev/null -s /bin/false pcguest</nowiki>}}
 +
 
 +
Then setup a "" password for user pcguest.
 +
 
 +
The last step is to create share directory (for write access make writable = yes):
 +
 
 +
{{bc|<nowiki>
 +
[Public Share]
 +
path = /path/to/public/share
 +
available = yes
 +
browsable = yes
 +
public = yes
 +
writable = no
 +
</nowiki>}}
 +
 
 +
{{note|Make sure the guest also has permission to visit /path, /path/to and /path/to/public, according to [http://unix.stackexchange.com/questions/13858/do-the-parent-directorys-permissions-matter-when-accessing-a-subdirectory http://unix.stackexchange.com/questions/13858/do-the-parent-directorys-permissions-matter-when-accessing-a-subdirectory]}}
 +
 
 +
==== Sample Passwordless Configuration ====
 +
This is the configuration I use with samba 4 for easy passwordless filesharing with family on a home network. Change any options needed to suit your network (workgroup and interface). I'm restricting it to the static IP I have on my ethernet interface, just delete that line if you do not care which interface is used.
 +
{{hc|/etc/samba/smb.conf|<nowiki>
 +
[global]
 +
 
 +
  workgroup = WORKGROUP
 +
 
 +
  server string = Media Server
 +
 
 +
  security = user
 +
  map to guest = Bad User
 +
 
 +
  log file = /var/log/samba/%m.log
 +
 
 +
  max log size = 50
  
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 disuade users from wasting space with certain files:
 
  
Veto files = /*.exe/*.com/*.dll/*.bat/*.vbs/*.tmp/*.mp3/*.avi/*.mp4/*.wmv/*.wma/
+
  interfaces = 192.168.2.194/24
 +
 
 +
 
 +
  dns proxy = no
 +
 
 +
 
 +
[media]
 +
  path = /shares
 +
  public = yes
 +
  only guest = yes
 +
  writable = yes
 +
 
 +
[storage]
 +
  path = /media/storage
 +
  public = yes
 +
  only guest = yes
 +
  writable = yes
 +
</nowiki>}}
 +
 
 +
=== Build Samba without CUPS ===
 +
 
 +
Just build without cups installed. From the [https://wiki.samba.org/index.php/Samba_as_a_print_server Samba Wiki]:
 +
<blockquote>Samba has built-in support [for CUPS] and defaults to CUPS if the development package (aka header files and libraries) could be found at compile time.</blockquote>
 +
 
 +
Of course, modifications to the PKGBUILD will also be necessary: libcups will have to be removed from the depends and makedepends arrays and other references to cups and printing will need to be deleted. In the case of the 4.1.9-1 PKGBUILD, 'other references' includes lines 169, 170 and 236:
 +
{{bc|
 +
    mkdir -p ${pkgdir}/usr/lib/cups/backend
 +
    ln -sf /usr/bin/smbspool ${pkgdir}/usr/lib/cups/backend/smb
 +
  install -d -m1777 ${pkgdir}/var/spool/samba
 +
}}
  
 
== Troubleshooting ==
 
== Troubleshooting ==
 +
 +
=== Failed to start Samba SMB/CIFS server ===
 +
 +
Check if the permissions are set correctly for {{ic|/var/cache/samba/}} and restart the {{ic|smbd.service}} or {{ic|smbd.socket}}:
 +
# chmod 0755 /var/cache/samba/msg
 +
 +
=== Unable to overwrite files, permissions errors ===
 +
Possible solutions:
 +
*Append the mount option {{ic|nodfs}} to the {{ic|/etc/fstab}} [[#As_mount_entry|entry]].
 +
*Add {{ic|<nowiki>msdfs root = no</nowiki>}} to the {{ic|[global]}} section of the server's {{ic|/etc/samba/smb.conf}}.
 +
 +
=== Windows clients keep asking for password even if Samba shares are created with guest permissions ===
 +
Set {{ic|map to guest}} inside the {{ic|global}} section of {{ic|/etc/samba/smb.conf}}:
 +
map to guest = Bad User
 +
 
=== Windows 7 connectivity problems - mount error(12): cannot allocate memory ===
 
=== 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:
 
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)
+
*{{ic|HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\LargeSystemCache}} (set to {{ic|1}})
*HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\Size (set to 3)
+
*{{ic|HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\Size}} (set to {{ic|3}})
 
 
  
Alternatively, in Command Prompt (make sure it is executed in Admin Mode):
+
Alternatively, start Command Prompt in Admin Mode and execute the following:
{{bc|
 
 
  reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" /v "LargeSystemCache" /t REG_DWORD /d 1 /f
 
  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
 
  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].
 +
 +
=== 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}}:
 +
{{bc|<nowiki>
 +
load printers = No
 +
printing = bsd
 +
printcap name = /dev/null
 +
disable spoolss = Yes
 +
</nowiki>}}
 +
[[Restart]] the samba service, {{ic|smbd.service}}, and then check your logs:
 +
{{bc|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 [[#Creating usershare path]].
 +
 +
=== "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) local 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:{{bc|
 +
iptables -t raw -A OUTPUT -p udp -m udp --dport 137 -j CT --helper netbios-ns
 
}}
 
}}
 +
to your iptables setup.
  
Restart the Windows machine for the settings to take effect.
+
=== "Browsing" network lead to an empty folder ===
 +
Despite a working and well configured samba, browsing network for Windows shares using a {{Pkg|gvfs}} based file manager (Nautilus, PCManFM, and others) it does only get an empty folder.
 +
With samba 4.7 are changed the default protocols and this seems to cause problems with browsers.
 +
For a temporary workaround you can add the following parameter in the {{ic|smb.conf}} configuration file:
  
{{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.}}
+
{{hc|/etc/samba/smb.conf|2=
 +
...
 +
[global]
 +
  client max protocol = NT1
 +
  ...
 +
}}
  
[http://alan.lamielle.net/2009/09/03/windows-7-nonpaged-pool-srv-error-2017 Link] to original article.
+
=== Protocol negotiation failed: NT_STATUS_INVALID_NETWORK_RESPONSE ===
  
=== Trouble accessing a password-protected share from Windows ===
+
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}}.
  
For trouble accessing a password protected share from Windows, try adding this to {{ic|/etc/samba/smb.conf}}:[http://blogs.computerworld.com/networking_nightmare_ii_adding_linux]
+
=== Connection to SERVER failed: (Error NT_STATUS_UNSUCCESSFUL) ===
  
Note that this needs to be added to the '''local''' smb.conf, not to the server's smb.conf
+
You are probably passing wrong server name to {{ic|smbclient}}.  To find out the server name, run {{ic|hostnamectl}} on the server and look at "Transient hostname" line
  
[global]
+
=== Connection to SERVER failed: (Error NT_STATUS_CONNECTION_REFUSED) ===
# lanman fix
 
client lanman auth = yes
 
client ntlmv2 auth = no
 
  
=== Getting a dialog box up takes a long time ===
+
Make sure that the server has started. The shared directories should exist and be accessible.
  
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:
+
=== 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}}.
  
[2009/11/11 06:20:12,  0] printing/print_cups.c:cups_connect(103)
+
=== Password Error when correct credentials are given (error 1326) ===
Unable to connect to CUPS server localhost:631 - Interrupted system call
+
[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.
 +
 +
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
 +
}}
  
This keeps samba from asking cups and also from complaining about /etc/printcap missing:
+
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
 +
}}
  
printing = bsd
+
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.
printcap name = /dev/null
 
  
=== Changes in Samba version 3.4.0 ===
+
mount.cifs //server/share /mnt/point -o sec=ntlmssp,...
  
[http://www.samba.org/samba/history/samba-3.4.0.html Major enhancements in Samba 3.4.0] include:
+
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'''.
  
The default passdb backend has been changed to 'tdbsam'! That breaks existing setups using the 'smbpasswd' backend without explicit declaration!
+
=== Mapping reserved Windows characters ===
  
To stick to the 'smbpasswd' backend try changing this in {{ic|/etc/samba/smb.conf}}:
+
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.
  
passdb backend = smbpasswd
+
Possible solutions are:
 +
* Use the undocumented {{ic|nomapposix}} mount option for cifs
  
or convert the smbpasswd entries using:
+
  # mount.cifs //server/share /mnt/point -o nomapposix
  
sudo pdbedit -i smbpasswd -e tdbsam
+
* 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]
  
=== Error: Value too large for defined data type ===
+
{{hc|/etc/samba/smb.conf|2=
 +
[global]
 +
  vfs objects = catia fruit
 +
  fruit:encoding = native
 +
}}
  
Some applications might encounter this error whith every attempt to open a file mounted in smbfs/cifs:
+
* Manually remap forbidden characters using [https://www.mankier.com/8/vfs_catia catia]
  
  Value too large for defined data type
+
{{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 solution[https://bugs.launchpad.net/ubuntu/+bug/479266/comments/5] is to add this options to the smbfs/cifs mount options (in /etc/fstab for example):
+
The latter approach (using catia or fruit) has the drawback of filtering files with unprintable characters.
  
  ,nounix,noserverino
+
=== Folder shared inside graphical environment is not available to guests ===
  
''It works on Arch Linux up-to-date (2009-12-02)''
+
This section presupposes:
 +
# Usershares are configured following [[#Creating usershare path|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
  
=== I need to restart samba in order get my shares visible by other  ===
+
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
  
If upon booting, the samba shares cannot be accessed from any client, check the following:
+
==== Verify correct samba configuration ====
* Make sure that the samba daemon has been added 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.
 
  
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.
+
Run the following command from a terminal to test configuration file correctness:
  
In case starting samba in the correct order still doesn't help, try inserting a delay command into /etc/rc.d/samba:
+
  $ testparm
  #!/bin/bash
+
 
+
If everything is fine among output lines you may read
. /etc/rc.conf
+
 
. /etc/rc.d/functions
+
{{ic|Press enter to see a dump of your service definitions}}
[ -f /etc/conf.d/samba ] && . /etc/conf.d/samba
+
 
+
If it is not, please correct file accordingly to command error notifications.
[ -z "$SAMBA_DAEMONS" ] && SAMBA_DAEMONS=(smbd nmbd)
+
 
+
Press the Enter key in order to dump samba configuration.
case "$1" in
+
The following options must be listed.
        start)
 
                rc=0
 
                stat_busy "Starting Samba Server"
 
                sleep 5
 
                if [ ! -x /var/run/samba ] ; then
 
# rest of the file not posted here.
 
  
Only the '''sleep 5''' line is inserted, everything else is as from the Arch repositories.
+
{{hc|/etc/samba/smb.conf|2=
It causes a delay of 5 seconds before starting the samba server. In order to avoid the additional boot-time,  start the Samba daemon in background, as described above.
+
[global]
  
The file /etc/rc.d/samba is part of the samba package, though. Therefore, manually apply this change every time Samba gets updated.
+
  ... some options here ...
  
=== Sharing a folder fails  ===
+
        usershare max shares = 100
 +
        usershare path = /var/lib/samba/usershare
 +
        map to guest = Bad Password
  
If sharing a folder from Dolphin (file manager) and everything seems ok at first, but after restarting Dolphin (file manager) the share icon is gone from the shared folder, and also some output like this in terminal (Konsole) output:
+
   ... other options here ...
‘net usershare’ returned error 255: net usershare: usershares are currently disabled
 
Do the following:
 
 
Open {{ic|/etc/samba/smb.conf}} as root and edit the section {{ic|[global]}}:
 
   [global]
 
  '''.....'''
 
  usershare allow guests = Yes
 
  usershare max shares = 100
 
  usershare owner only = False
 
  '''.....'''
 
close the file and do the following afterwards:{{bc|
 
# mkdir /var/lib/samba/usershares
 
# chgrp users /var/lib/samba/usershares/
 
# chmod 1775 /var/lib/samba/usershares/
 
# chmod +t /var/lib/samba/usershares/
 
 
}}
 
}}
restart {{ic|samba}} [[daemon]]
 
  
==See also==
+
If previous option are not present, modify {{ic|/etc/samba/smb.conf}} file in order to add them all.
* [http://www.samba.org/ Samba's official site]
+
{{Note|The ''map to guest'' option is used in order to avoid user/password prompt from Windows users.}}
 +
 
 +
==== Verify correct shared folder creation ====
 +
 
 +
Run the following commands from a terminal:
 +
 
 +
$ cd /var/lib/samba/usershare
 +
$ ls
 +
 
 +
If everything is fine, you will notice a file named {{ic|mysharedfiles}}
 +
 
 +
Read the file contents using the following command:
 +
 
 +
$ cat mysharedfiles
 +
 
 +
The terminal output should display something like this:
 +
 
 +
{{hc|/var/lib/samba/usershare/mysharedfiles|2=
 +
path=/home/yourUser/Shared
 +
comment=
 +
usershare_acl=S-1-1-0:r
 +
guest_ok=y
 +
sharename=MySharedFiles}}
 +
 
 +
==== Verify folder access by guest ====
 +
 
 +
Run the following command from a terminal. If prompted for a password, just press Enter:
 +
 
 +
$ smbclient -L localhost
 +
 
 +
If everything is fine, MySharedFiles should be displayed under {{ic|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:
 +
 
 +
{{ic|smb: \>}}
 +
 
 +
From samba prompt verify guest can list directory contents:
 +
 
 +
{{ic|smb: \> ls}}
 +
 
 +
If {{ic|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.
 +
 
 +
== See also ==
 +
 
 
* [http://www.samba.org/samba/docs/SambaIntro.html Samba: An Introduction]
 
* [http://www.samba.org/samba/docs/SambaIntro.html Samba: An Introduction]
 +
* [http://www.samba.org/ Official Samba site]

Latest revision as of 22:16, 13 December 2017

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 configuration

To share files with Samba, install the samba package.

smb.conf

Samba is configured in /etc/samba/smb.conf, if this file doesn't exist smbd will fail to start.

To get started you can copy the default config file from samba git repository to /etc/samba/smb.conf.

Tip: The default configuration sets log file to a non-writable location, which will cause errors - it's better to change it to something arch-friendly: log file = /var/log/samba/%m.log.

The available options are documented in the smb.conf(5) man page. Whenever you modify the file run the testparm(1) command to check for syntactic errrors.

Creating a share

Open /etc/samba/smb.conf, and scroll down to the Share Definitions section. The default configuration automatically creates a share for each user's home directory.

The workgroup specified in smb.conf has to match the in use Windows workgroup (default WORKGROUP).

Starting services

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

Tip: Instead of having the service running since boot, you can enable smbd.socket so the daemon is started on the first incoming connection. Do not forget to disable smbd.service.

Creating usershare path

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

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

This creates the usershare directory in /var/lib/samba:

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

This creates the group sambashare:

# groupadd -r sambashare

This changes the owner of the directory to root and the group to sambashare:

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

This changes the permissions of the usershare directory so that users in the group sambashare can read, write and execute files:

# chmod 1770 /var/lib/samba/usershare

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

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

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

# gpasswd sambashare -a your_username

Restart smbd.service and nmbd.service services.

Log out and log back in. You should now be able to configure your samba share using GUI. For example, in Thunar you can right click on any directory and share it on the network. If you want to share paths inside your home directory you must make it listable for the group others.

Adding a user

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

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 username
  • 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 Samba user's password

To change a user's password, use smbpasswd:

# smbpasswd samba_user

Required ports

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

Client configuration

For a lightweight method (without support for listing public shares, etc.), only install cifs-utils to provide /usr/bin/mount.cifs.

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

Note: smbclient requires an /etc/samba/smb.conf file which the utility, touch, can generate (as an empty file), or if samba is installed, it can be copied from the default #smb.conf.

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

Note: After installing cifs-utils or smbclient, load the 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 -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/enable winbindd in order to resolve host names with e.g., mount.cifs

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.

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 user=username,password=password,uid=username,gid=group,workgroup=workgroup,ip=serverip,iocharset=utf8

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.

Note: The option is users (plural). For other filesystem types handled by mount, this option is usually user; sans the "s".
Warning: Using uid and/or gid as mount options may cause I/O errors, it's recommended to set/check the 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 create a credentials file:

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

Replace username=myuser,password=mypass with credentials=/path/to/credentials/share.

The credential file should explicitly readable/writeable to root:

# chmod 600 /path/to/credentials/share

Automatic mounting

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

As mount entry

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

/etc/fstab
//SERVER/sharename /mnt/mountpoint cifs username=myuser,password=mypass 0 0
Note: Space 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.

To speed up the service on boot, add the x-systemd.automount option to the entry:

/etc/fstab
//SERVER/SHARENAME /mnt/mountpoint cifs credentials=/path/to/smbcredentials/share,x-systemd.automount 0 0

As systemd unit

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

Note: Make sure the filename corresponds to the mountpoint you want to use.

E.g. the unit name mnt-myshare.mount can only be used if are going to mount the share under /mnt/myshare. Otherwise the following error might occur: "systemd[1]: mnt-myshare.mount: Where= setting doesn't match unit name. Refusing."

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

What= path to share

Where= path to mount the share

Options= share mounting options

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

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

[Install]
WantedBy=multi-user.target

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

smbnetfs

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

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

$ smbtree -U remote_user

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

domain master = auto

Now restart smbd.service and nmbd.service.

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

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

user_allow_other

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

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

Then create a link to smb.conf:

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

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

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

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

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

~/.smb/smbnetfs.conf
free_space_size 1073741824

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

$ chmod 600 ~/.smb/smbnetfs.*

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

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

$ smbnetfs mount_point
Daemon

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

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

autofs

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

File manager configuration

GNOME Files, Nemo, Caja, Thunar and PCManFM

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

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

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

KDE

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

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

Improve performance

Tango-view-fullscreen.pngThis article or section needs expansion.Tango-view-fullscreen.png

Reason: Add explanations. (Discuss in Talk:Samba#)
/etc/samba/smb.conf
[global]
        server multi channel support = yes
        socket options = IPTOS_THROUGHPUT SO_KEEPALIVE
        deadtime = 30
        use sendfile = Yes
        write cache size = 262144
        min receivefile size = 16384
        aio read size = 16384
        aio write size = 16384
        nt pipe support = no
Warning: nt pipe support = no breaks some windows functionality.

Disable printer share

If you do not have printers to be shared, use the following setting to save some resources:

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

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/

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

Share files without a username and password

Edit /etc/samba/smb.conf and add the following line:

map to guest = Bad User

After this line:

security = user

Restrict the shares data to a specific interface replace:

;   interfaces = 192.168.12.2/24 192.168.13.2/24

with:

interfaces = lo eth0
bind interfaces only = true

Optionally edit the account that access the shares, edit the following line:

;   guest account = nobody

For example:

   guest account = pcguest

And do something in the likes of:

# useradd -c "Guest User" -d /dev/null -s /bin/false pcguest

Then setup a "" password for user pcguest.

The last step is to create share directory (for write access make writable = yes):

[Public Share]
path = /path/to/public/share
available = yes
browsable = yes
public = yes
writable = no
Note: Make sure the guest also has permission to visit /path, /path/to and /path/to/public, according to http://unix.stackexchange.com/questions/13858/do-the-parent-directorys-permissions-matter-when-accessing-a-subdirectory

Sample Passwordless Configuration

This is the configuration I use with samba 4 for easy passwordless filesharing with family on a home network. Change any options needed to suit your network (workgroup and interface). I'm restricting it to the static IP I have on my ethernet interface, just delete that line if you do not care which interface is used.

/etc/samba/smb.conf
[global]

   workgroup = WORKGROUP

   server string = Media Server

   security = user
   map to guest = Bad User

   log file = /var/log/samba/%m.log

   max log size = 50


   interfaces = 192.168.2.194/24


   dns proxy = no 


[media]
   path = /shares
   public = yes
   only guest = yes
   writable = yes

[storage]
   path = /media/storage
   public = yes
   only guest = yes
   writable = yes

Build Samba without CUPS

Just build without cups installed. From the Samba Wiki:

Samba has built-in support [for CUPS] and defaults to CUPS if the development package (aka header files and libraries) could be found at compile time.

Of course, modifications to the PKGBUILD will also be necessary: libcups will have to be removed from the depends and makedepends arrays and other references to cups and printing will need to be deleted. In the case of the 4.1.9-1 PKGBUILD, 'other references' includes lines 169, 170 and 236:

    mkdir -p ${pkgdir}/usr/lib/cups/backend
    ln -sf /usr/bin/smbspool ${pkgdir}/usr/lib/cups/backend/smb
  install -d -m1777 ${pkgdir}/var/spool/samba

Troubleshooting

Failed to start Samba SMB/CIFS server

Check if the permissions are set correctly for /var/cache/samba/ and restart the smbd.service or smbd.socket:

# chmod 0755 /var/cache/samba/msg

Unable to overwrite files, permissions errors

Possible solutions:

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

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.

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:

load printers = No
printing = bsd
printcap name = /dev/null
disable spoolss = Yes

Restart the samba service, smbd.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 #Creating usershare path.

"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) local 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.

"Browsing" network lead to an empty folder

Despite a working and well configured samba, browsing network for Windows shares using a gvfs based file manager (Nautilus, PCManFM, and others) it does only get an empty folder. With samba 4.7 are changed the default protocols and this seems to cause problems with browsers. For a temporary workaround you can add the following parameter in the smb.conf configuration file:

/etc/samba/smb.conf
...
[global]
  client max protocol = NT1
  ...

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.

Connection to SERVER failed: (Error NT_STATUS_UNSUCCESSFUL)

You are probably passing 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

If everything is fine among output lines you may read

Press enter to see a dump of your service definitions

If it is not, please correct file accordingly to command error notifications.

Press the Enter key in order to dump samba configuration. The following options must be listed.

/etc/samba/smb.conf
[global]

   ... some options here ...

        usershare max shares = 100
        usershare path = /var/lib/samba/usershare
        map to guest = Bad Password

   ... other options here ...

If previous option are not present, modify /etc/samba/smb.conf file in order to add them all.

Note: The map to guest option is used in order to avoid user/password prompt from Windows users.

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.

See also