Difference between revisions of "Samba"

From ArchWiki
Jump to: navigation, search
(Adding the share to {{ic|fstab}}: out-of-date)
(Undo revision 248341 by Geza83 (talk) this is not preferred: see Style guide)
(13 intermediate revisions by 7 users not shown)
Line 11: Line 11:
 
[[zh-CN:Samba]]
 
[[zh-CN:Samba]]
 
[[zh-TW:Samba]]
 
[[zh-TW:Samba]]
 +
[[ja:Samba]]
 
{{Article summary start|Summary}}
 
{{Article summary start|Summary}}
 
{{Article summary text|Installing, configuring and troubleshooting Samba}}
 
{{Article summary text|Installing, configuring and troubleshooting Samba}}
Line 18: Line 19:
 
{{Article summary end}}
 
{{Article summary 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.
 
  
==Installation==
+
'''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.
  
Installing only the {{Pkg|smbclient}}, available in the [[Official Repositories]], is sufficient for systems that are not meant to share files, only access them.
+
==Required packages==
 +
===Server===
 +
To share files with Samba, install {{Pkg|samba}}, from the [[Official Repositories]].
  
In order to make shares available to clients, install {{Pkg|samba}}, available in the [[Official Repositories]].
+
===Client===
 +
Only {{Pkg|smbclient}} is required to access files from a Samba/SMB/CIFS server. It is also available from the Official Repositories.
  
==Configuration==
+
==Server configuration==
=== Basic Setup ===
+
The {{ic|/etc/samba/smb.conf}} file must be created before starting the service. Once that is set up, users may opt for using an advanced configuration interface like SWAT.
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}}:
 
As root, copy the default Samba configuration file to {{ic|/etc/samba/smb.conf}}:
 
{{bc|# cp /etc/samba/smb.conf.default /etc/samba/smb.conf}}
 
{{bc|# cp /etc/samba/smb.conf.default /etc/samba/smb.conf}}
  
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===
 +
Edit {{ic|/etc/samba/smb.conf}}, scroll down to the '''Share Definitions''' section. The default configuration automatically creates a share for each user's home directory. It also creates a share for printers by default.
  
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.
+
There are a number of commented sample configurations included. More information about available options for shared resources can be found in {{ic|man smb.conf}}. [http://www.samba.org/samba/docs/man/manpages-3/smb.conf.5.html Here] is the on-line version.
  
Start Samba via the '''smbd''' and '''nmbd''' [[daemon]]s.
+
===Adding a user===
 
+
To log into a Samba share, a samba user is needed. The user '''must''' already have a [[Users and Groups|Linux user account]] with the same name on the server, otherwise running the next command will fail:
{{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.}}
+
 
+
=== Shell Based Options ===
+
====Adding users====
+
To log into a Samba share, a samba user is needed.
+
 
  # pdbedit -a -u <user>
 
  # 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>}}.
+
{{Note|As of version 3.4.0, smbpasswd is no longer used by default. Existing smbpasswd databases can be [[Samba/Troubleshooting#Changes_in_Samba_version_3.4.0|converted to the new format]]}}
 
+
{{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]]}}
+
 
+
===Web Based Option ===
+
====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.
+
  
{{Note|An all-encompasing [[Webmin]] tool instead can also be used, and easily load the SWAT module there.}}
+
=== Web-based configuration (SWAT)===
 +
'''SWAT''' (Samba Web Administration Tool) is a facility that is part of the Samba suite. Whether or not to use this tool remains a matter of personal preference. It does allow for quick configuration and has context-sensitive help for each {{ic|smb.conf}} parameter. SWAT also provides an interface for monitoring of current state of connection(s), and allows network-wide MS Windows network password management.
  
{{Warning|Before using SWAT, be warned that SWAT will completely replace {{ic|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.}}
+
{{Warning|Before using SWAT, be warned that SWAT will completely replace {{ic|/etc/samba/smb.conf}} with a fully optimized file that has been stripped of all comments, and only non-default settings will be written to the file.}}
  
 
To use SWAT, first install {{Pkg|xinetd}}, available in the [[Official Repositories]].
 
To use SWAT, first install {{Pkg|xinetd}}, available in the [[Official Repositories]].
Line 64: Line 55:
 
Edit {{ic|/etc/xinetd.d/swat}}. To enable SWAT, change the {{ic|1=disable = yes}} line to {{ic|1=disable = no}}.
 
Edit {{ic|/etc/xinetd.d/swat}}. To enable SWAT, change the {{ic|1=disable = yes}} line to {{ic|1=disable = no}}.
  
{{bc|<nowiki>
+
{{hc|/etc/xinetd.d/swat|<nowiki>
 
service swat
 
service swat
 
{
 
{
Line 77: Line 68:
 
         log_on_failure          += HOST
 
         log_on_failure          += HOST
 
         disable                = no
 
         disable                = no
}
+
}</nowiki>}}
</nowiki>
+
}}
+
  
 
Alternatively, add an entry for swat to {{ic|/etc/services}} and omit the first 3 lines of the configuration.
 
Alternatively, add an entry for swat to {{ic|/etc/services}} and omit the first 3 lines of the configuration.
  
Then start xinetd [[daemon]].
+
Then start the "xinetd" [[Daemons|daemon]].
  
 
The web interface can be accessed on port 901 by default:
 
The web interface can be accessed on port 901 by default:
 
{{ic|http://localhost:901/}}
 
{{ic|http://localhost:901/}}
  
==Accessing shares==
+
{{Note|An all-encompasing [[Webmin]] tool is also available, and the SWAT module can be loaded there.}}
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.
+
=== Starting the service ===
 +
Start/enable Samba via the '''smbd''' and '''nmbd''' [[daemon]]s.
  
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.
+
==Client configuration==
 +
Shared resources from other computers on the LAN may be accessed and mounted locally by GUI or CLI methods. The graphical manner is limited since most lightweight Desktop Environments do not have a native way to facilitate accessing these shared resources.
  
===Accessing a Samba share from GNOME/Xfce4/LXDE===
+
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.
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]].
+
===Manual mounting===
 +
Install {{pkg|smbclient}} from the [[Official Repositories]].
  
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:
+
To list  public shares on a server:
{{ic|smb://servername/share}}
+
{{bc|$ smbclient -L <hostname> -U%}}
  
{{Note|If the servername is not in {{ic|/etc/hosts}}, use the IP address of the server in place of the servername.}}
+
Create a mount point for the share:
 +
{{bc|# mkdir /mnt/MOUNTPOINT}}
  
From a Pcmanfm window, under the "Go" menu choose "Network Files".
+
Mount the share using the {{ic|mount.cifs}} type. Not all the options listed below are needed or desirable (ie. {{ic|password}}).
 +
{{bc|# <nowiki>mount -t cifs //SERVER/SHARENAME /mnt/MOUNTPOINT -o user=USERNAME,password=PASSWORD,workgroup=WORKGROUP,ip=SERVERIP</nowiki>}}
 +
{{ic|'''SERVER'''}}
 +
:The Windows system name.
 +
{{ic|'''SHARENAME'''}}
 +
:The shared directory.
 +
{{ic|'''MOUNTPOINT'''}}
 +
:The local directory where the share will be mounted.
 +
{{ic|'''-o <nowiki>[options]</nowiki>'''}}
 +
:See {{ic|man mount.cifs}} for more information:
 +
{{Note|Abstain from using a trailing '''/'''. {{ic|//SERVER/SHARENAME'''/'''}} will not work.}}
 +
====Add Share to /etc/fstab====
 +
The simplest way to add an fstab entry is something like this:
 +
{{hc|/etc/fstab|<nowiki>
 +
//SERVER/SHARENAME /mnt/MOUNTPOINT cifs noauto,username=USER,password=PASSWORD,workgroup=WORKGROUP,ip=SERVERIP 0 0</nowiki>}}
 +
However, storing passwords in a world readable file is not recommended! A safer method would be to use a credentials file. As an example, create a file and {{ic|chmod 600 <filename>}} so only the owning user can read and write to it. It should contain the following information:
 +
{{hc|/path/to/credentials/sambacreds|<nowiki>
 +
username=USERNAME
 +
password=PASSWORD</nowiki>}}
 +
and the line in your fstab should look something like this:
 +
{{hc|/etc/fstab|<nowiki>
 +
//SERVER/SHARENAME /mnt/MOUNTPOINT cifs noauto,username=USER,credentials=/path/to/credentials/sambacreds,workgroup=WORKGROUP,ip=SERVERIP 0 0</nowiki>}}
 +
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:
 +
{{hc|/etc/fstab|<nowiki>//SERVER/SHARENAME /mnt/MOUNTPOINT cifs noauto,credentials=/path/to/smbcredentials,comment=systemd.automount,uid=USERNAME,gid=USERGROUP 0 0</nowiki>}}
  
Another GNOME browser program is Gnomba.
+
====User mounting====
 +
{{hc|/etc/fstab|<nowiki>//SERVER/SHARENAME /mnt/MOUNTPOINT cifs users,noauto,credentials=/path/to/smbcredentials,workgroup=WORKGROUP,ip=SERVERIP 0 0</nowiki>}}
 +
{{note|Note: The option is user'''s''' (plural). For other filesystem types handled by mount, this option is usually ''user''; sans the "'''s'''".}}
  
If iptables is running, the '''nf_conntrack_netbios_ns''' module should be loaded:
+
This will 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. For users to be allowed to mount and unmount the Samba shares with mount points that they do not own, use [[Samba#smbnetfs|smbnetfs]], or grant privileges using [[sudo]].
modprobe nf_conntrack_netbios_ns
+
  
===Accessing shares from other graphical environments===
+
===Automatic Mounting===
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.
+
There are several ways to easily browse shared resources:
 +
====smbnetfs====
 +
Install {{pkg|smbnetfs}}, from the [[Official Repositories]].
  
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.
+
Add the following line to {{ic|/etc/fuse.conf}}:
 +
{{bc|user_allow_other}}
 +
and load the {{ic|fuse}} [[kernel module]]:
 +
{{bc|# modprobe fuse}}
  
Other possible programs include pyneighborhood and RUmba, as well as the xffm-samba plugin for Xffm.
+
If a username and a password are required to access some of the shared folders, edit /etc/smbnetfs/.smb/smbnetfs.conf and uncomment the line starting with "auth":
  
===Accessing a Samba share from the shell===
+
{{hc|/etc/smbnetfs/.smb/smbnetfs.conf|
Shares may be accessed by using an automatic mounter or by using a [[#Manual share mounting|manual method]].
+
auth "hostname" "username" "password"
 +
}}
  
====Automatic share mounting====
+
Make sure to {{ic|chmod 600 /etc/smbnetfs/.smb/smbnetfs.conf}}, and any include files for smbnetfs to work correctly.
There are several alternatives for easy share browsing.
+
  
=====smbnetfs=====
+
===== Daemon =====
Install {{Pkg|smbnetfs}}, available in the [[Official Repositories]].
+
Start and enable the '''smbnetfs''' [[daemon]].
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}}.
+
====fusesmb====
 
+
To access the shares at boot:
+
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":
+
 
+
auth "hostname" "username" "password"
+
 
+
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:
+
 
+
# chmod 600 /etc/smbnetfs/.smb/smbnetfs.conf
+
 
+
=====fusesmb=====
+
 
{{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.}}
 
{{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.}}
  
Line 154: Line 156:
 
# Mount the shares: {{bc|# fusesmb -o allow_other /mnt/fusesmb}}
 
# Mount the shares: {{bc|# fusesmb -o allow_other /mnt/fusesmb}}
  
=====Autofs=====
+
====autofs====
 
See [[Autofs]] for information on the kernel-based automounter for Linux.
 
See [[Autofs]] for information on the kernel-based automounter for Linux.
  
====Manual share mounting====
+
===File Manager Configuration===
1. Use [[smbclient]] to browse shares from the shell. To list any public shares on a server:
+
====Nautilus====
$ smbclient -L <hostname> -U%
+
In order to access samba shares through Nautilus, install the {{pkg|gvfs-smb}} and {{pkg|gnome-vfs}} packages, available in the [[Official Repositories]].
  
2. Create the mount point for the share:
+
Press {{keypress|Ctrl+L}} and enter {{ic|smb://servername/share}} in the location bar to access your share.
# mkdir /mnt/MOUNTPOINT
+
  
3. Mount the share using {{ic|mount.cifs}}. Keep in mind that not all options may be needed nor desirable, such as {{ic|password}}:
+
The mounted share is likely to be present at {{ic|/run/user/<your UID>/gvfs}} in the filesystem.
# mount -t cifs //''SERVER''/''SHARENAME'' ''/mnt''/''MOUNTPOINT'' -o user=''USERNAME'',password=''PASSWORD'',workgroup=''WORKGROUP'',ip=''SERVERIP''
+
  
;{{ic|SERVER}}: The Windows system's name
+
====Thunar and pcmanfm====
;{{ic|SHARENAME}}: The shared directory
+
For access using Thunar or pcmanfm, install {{pkg|gvfs-smb}}, available in the Official Repositories.  
;{{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.}}
+
Go to {{ic|smb://servername/share}}, to access your share.
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).
+
  
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.
+
====KDE====
 +
KDE, has the ability to browse Samba shares built in. Therefore do not need any additional packages. However, for a GUI in the KDE System Settings, install the {{pkg|kdenetwork-filesharing}} package from the [[Official Repositories]]
  
4. To unmount the share, use:
+
====Other Graphical Environments====
# umount /mnt/MOUNTPOINT
+
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.
  
=====Adding the share to {{ic|fstab}}=====
+
* {{pkg|pyneighborhood}} is available in the [[Official Repositories]].
Add the following to {{ic|/etc/[[fstab]]}} for easy mounting:
+
* 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.
//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
 
 
After adding the previous line, the syntax to mount files becomes simpler:
 
# mount /mnt/MOUNTPOINT
 
 
Another option, to keep passwords out of sight, is to use the 'credentials' option:
 
//SERVER/SHARENAME /path/to/SHAREMOUNT cifs noauto,credentials=/path/to/smbcredentials 0 0
 
 
The credentials file should contain the following text:
 
username=USERNAME
 
password=PASSWORD
 
 
It is highly recommended to <tt>chmod 600</tt> this file so that only the owning user can read and write to it.
 
 
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:
 
//SERVER/SHARENAME /path/to/SHAREMOUNT cifs credentials=/path/to/smbcredentials,'''comment=systemd.automount''','''uid=USERNAME,gid=USERGROUP''' 0 0
 
 
=====Allowing users to mount=====
 
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'''".}}
 
 
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]].
 
 
== Tips and tricks ==
 
 
=== Sample configuration file ===
 
 
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.
 
 
See [http://www.samba.org/samba/docs/man/manpages-3/smb.conf.5.html smb.conf] for details and explanation of configuration options.
 
 
<nowiki>
 
[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
 
 
    create mask = 0664
 
    directory mask = 0775
 
 
    force create mode = 0664
 
    force directory mode = 0775
 
 
    ; One may be interested in the following setting:
 
    ;force group = +nas
 
 
[media1]
 
    path = /media/media1
 
    read only = No
 
 
[media2]
 
    path = /media/media2
 
    read only = No
 
 
[media3]
 
    path = /media/media3
 
    read only = No
 
</nowiki>
 
 
Remember to <code>testparm -s</code> and <code>systemctl restart smbd nmbd</code> after editing configuration files.
 
 
=== Share files without a username and password ===
 
 
 
Edit {{ic|/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
 
 
=== Samba Security ===
 
An extra layer of security can be obtainded by restricting your acceptable networks in the /etc/samba/smb.conf file:
 
 
hosts deny = 0.0.0.0/0
 
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:
 
 
UDP/137 - used by nmbd
 
UDP/138 - used by nmbd
 
TCP/139 - used by smbd
 
TCP/445 - used by smbd
 
 
So a series of commands like this should suffice:
 
 
# iptables -A INPUT -p tcp --dport 139 -j ACCEPT
 
# 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.
 
 
=== Adding network shares using KDE4 GUI ===
 
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 ===
 
 
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 {{Pkg|nmap}} and {{Pkg|smbclient}} using [[pacman]]:
 
# pacman -S nmap smbclient
 
 
2. {{ic|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:
 
{{hc
 
|$ nmap -sT 192.168.1.*
 
|Starting nmap 3.78 ( http://www.insecure.org/nmap/ ) at 2005-02-15 11:45 PHT
 
Interesting ports on 192.168.1.1:
 
(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 {{ic|nmblookup}} to check for NetBIOS names:
 
{{hc
 
|$ 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 {{ic|smbclient}} to list which services are shared on ''PUTER''. If prompted for a password, pressing enter should still display the list:
 
{{hc
 
|$ smbclient -L \\PUTER
 
|<nowiki>
 
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
 
</nowiki>}}
 
 
This shows which folders are shared and can be mounted locally. See: [[#Accessing shares]]
 
 
=== 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
 
 
=== Block certain file extensions on samba share ===
 
 
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/
 
 
== Troubleshooting ==
 
=== 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, in Command Prompt (make sure it is executed in Admin Mode):
 
{{bc|
 
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
 
}}
 
 
Restart the Windows machine for the settings to take effect.
 
 
{{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 Link] to original article.
 
 
=== Trouble accessing a password-protected share from Windows ===
 
 
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]
 
 
Note that this needs to be added to the '''local''' smb.conf, not to the server's smb.conf
 
 
[global]
 
# lanman fix
 
client lanman auth = yes
 
client ntlmv2 auth = no
 
 
=== Getting a dialog box up takes a long time ===
 
 
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:
 
 
[2009/11/11 06:20:12,  0] printing/print_cups.c:cups_connect(103)
 
Unable to connect to CUPS server localhost:631 - Interrupted system call
 
 
This keeps samba from asking cups and also from complaining about /etc/printcap missing:
 
 
printing = bsd
 
printcap name = /dev/null
 
 
=== Changes in Samba version 3.4.0 ===
 
 
[http://www.samba.org/samba/history/samba-3.4.0.html Major enhancements in Samba 3.4.0] include:
 
 
The default passdb backend has been changed to 'tdbsam'! That breaks existing setups using the 'smbpasswd' backend without explicit declaration!
 
 
To stick to the 'smbpasswd' backend try changing this in {{ic|/etc/samba/smb.conf}}:
 
 
passdb backend = smbpasswd
 
 
or convert the smbpasswd entries using:
 
 
sudo pdbedit -i smbpasswd -e tdbsam
 
 
=== Error: Value too large for defined data type ===
 
 
Some applications might encounter this error whith every attempt to open a file mounted in smbfs/cifs:
 
 
  Value too large for defined data type
 
 
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):
 
 
  ,nounix,noserverino
 
 
''It works on Arch Linux up-to-date (2009-12-02)''
 
 
=== I need to restart samba in order get my shares visible by other  ===
 
 
If upon booting, the samba shares cannot be accessed from any client, check the following:
 
* 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.
 
 
In case starting samba in the correct order still doesn't help, try inserting a delay command into /etc/rc.d/samba:
 
#!/bin/bash
 
 
. /etc/rc.conf
 
. /etc/rc.d/functions
 
[ -f /etc/conf.d/samba ] && . /etc/conf.d/samba
 
 
[ -z "$SAMBA_DAEMONS" ] && SAMBA_DAEMONS=(smbd nmbd)
 
 
case "$1" in
 
        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.
 
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.
 
 
The file /etc/rc.d/samba is part of the samba package, though. Therefore, manually apply this change every time Samba gets updated.
 
 
=== Sharing a folder fails  ===
 
 
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:
 
‘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==
 
==See also==
* [http://www.samba.org/ Samba's official site]
+
* [[{{FULLPAGENAME}}/Tips and tricks|Tips and tricks]] - A dedicated page for alternate configurations and suggestions.
 +
* [[{{FULLPAGENAME}}/Troubleshooting|Troubleshooting]] - A dedicated page for solving common (or not so common) issues.
 
* [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]

Revision as of 16:36, 24 February 2013

Summary help replacing me
Installing, configuring and troubleshooting Samba
Related
NFS
Samba Domain Controller


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.

Required packages

Server

To share files with Samba, install samba, from the Official Repositories.

Client

Only smbclient is required to access files from a Samba/SMB/CIFS server. It is also available from the Official Repositories.

Server configuration

The /etc/samba/smb.conf file must be created before starting the service. 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 /etc/samba/smb.conf:

# cp /etc/samba/smb.conf.default /etc/samba/smb.conf

Creating a share

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

There are a number of commented sample configurations included. More information about available options for shared resources can be found in man smb.conf. Here is the on-line version.

Adding a user

To log into a Samba share, a samba user is needed. The user must already have a Linux user account with the same name on the server, otherwise running the next command will fail:

# pdbedit -a -u <user>
Note: As of version 3.4.0, smbpasswd is no longer used by default. Existing smbpasswd databases can be converted to the new format

Web-based configuration (SWAT)

SWAT (Samba Web Administration Tool) is a facility that is part of the Samba suite. Whether or not to use this tool remains a matter of personal preference. It does allow for quick configuration and has context-sensitive help for each smb.conf parameter. SWAT also provides an interface for monitoring of current state of connection(s), and allows network-wide MS Windows network password management.

Warning: Before using SWAT, be warned that SWAT will completely replace /etc/samba/smb.conf with a fully optimized file that has been stripped of all comments, and only non-default settings will be written to the file.

To use SWAT, first install xinetd, available in the Official Repositories.

Edit /etc/xinetd.d/swat. To enable SWAT, change the disable = yes line to disable = no.

/etc/xinetd.d/swat
service swat
{
        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, add an entry for swat to /etc/services and omit the first 3 lines of the configuration.

Then start the "xinetd" daemon.

The web interface can be accessed on port 901 by default: http://localhost:901/

Note: An all-encompasing Webmin tool is also available, and the SWAT module can be loaded there.

Starting the service

Start/enable Samba via the smbd and nmbd daemons.

Client configuration

Shared resources from other computers on the LAN may be accessed and mounted locally by GUI or CLI methods. The graphical manner is limited since most lightweight Desktop Environments do not have a native way to facilitate accessing these shared resources.

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.

Manual mounting

Install smbclient from the Official Repositories.

To list public shares on a server:

$ smbclient -L <hostname> -U%

Create a mount point for the share:

# mkdir /mnt/MOUNTPOINT

Mount the share using the mount.cifs type. Not all the options listed below are needed or desirable (ie. password).

# mount -t cifs //SERVER/SHARENAME /mnt/MOUNTPOINT -o user=USERNAME,password=PASSWORD,workgroup=WORKGROUP,ip=SERVERIP

SERVER

The Windows system name.

SHARENAME

The shared directory.

MOUNTPOINT

The local directory where the share will be mounted.

-o [options]

See man mount.cifs for more information:
Note: Abstain from using a trailing /. //SERVER/SHARENAME/ will not work.

Add Share to /etc/fstab

The simplest way to add an fstab entry is something like this:

/etc/fstab
//SERVER/SHARENAME /mnt/MOUNTPOINT cifs noauto,username=USER,password=PASSWORD,workgroup=WORKGROUP,ip=SERVERIP 0 0

However, storing passwords in a world readable file is not recommended! A safer method would be to use a credentials file. As an example, create a file and chmod 600 <filename> so only the owning user can read and write to it. It should contain the following information:

/path/to/credentials/sambacreds
username=USERNAME
password=PASSWORD

and the line in your fstab should look something like this:

/etc/fstab
//SERVER/SHARENAME /mnt/MOUNTPOINT cifs noauto,username=USER,credentials=/path/to/credentials/sambacreds,workgroup=WORKGROUP,ip=SERVERIP 0 0

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:

/etc/fstab
//SERVER/SHARENAME /mnt/MOUNTPOINT cifs noauto,credentials=/path/to/smbcredentials,comment=systemd.automount,uid=USERNAME,gid=USERGROUP 0 0

User mounting

/etc/fstab
//SERVER/SHARENAME /mnt/MOUNTPOINT cifs users,noauto,credentials=/path/to/smbcredentials,workgroup=WORKGROUP,ip=SERVERIP 0 0
Note: Note: The option is users (plural). For other filesystem types handled by mount, this option is usually user; sans the "s".

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

Automatic Mounting

There are several ways to easily browse shared resources:

smbnetfs

Install smbnetfs, from the Official Repositories.

Add the following line to /etc/fuse.conf:

user_allow_other

and load the fuse kernel module:

# modprobe fuse

If a username and a password are required to access some of the shared folders, edit /etc/smbnetfs/.smb/smbnetfs.conf and uncomment the line starting with "auth":

/etc/smbnetfs/.smb/smbnetfs.conf
auth			"hostname" "username" "password"

Make sure to chmod 600 /etc/smbnetfs/.smb/smbnetfs.conf, and any include files for smbnetfs to work correctly.

Daemon

Start and enable the smbnetfs daemon.

fusesmb

Note: Because smbclient 3.2.X is malfunctioning with fusesmb, revert to using older versions if necessary. See the relevant forum topic for details.
  1. Install fusesmbAUR, available in the Arch User Repository.
  2. Create a mount point: # mkdir /mnt/fusesmb
  3. Load fuse kernel module.
  4. Mount the shares:
    # fusesmb -o allow_other /mnt/fusesmb

autofs

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

File Manager Configuration

Nautilus

In order to access samba shares through Nautilus, install the gvfs-smb and gnome-vfs packages, available in the Official Repositories.

Press Template:Keypress 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 in the filesystem.

Thunar and pcmanfm

For access using Thunar or pcmanfm, install gvfs-smb, available in the Official Repositories.

Go to smb://servername/share, to access your share.

KDE

KDE, has the ability to browse Samba shares built in. Therefore do not need any additional packages. However, for a GUI in the KDE System Settings, install the kdenetwork-filesharing package from the Official Repositories

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.


See also