From ArchWiki
Revision as of 03:56, 26 September 2012 by Jpkotta (talk | contribs) (Adding the share to {{ic|fstab}}: credentials file should be 600, not 700)
Jump to navigation Jump to search

zh-CN:Samba zh-TW:Samba Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary wiki Template: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 NFSv4. 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 smbclient, available in the Official Repositories, is sufficient for systems that are not meant to share files, only access them.

In order to make shares available to clients, install samba, available in the Official Repositories.


Basic Setup

The /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 /etc/samba/smb.conf:

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

Edit smb.conf. The default file creates a share for each user's home directory. It also creates a share for printers.

More information about the options available can be found in man smb.conf. Here is the online version.

To make samba work, start samba daemon or make it automatically start at boot.

Classic init

# rc.d start samba


# systemctl start smbd.service nmbd.service

Shell Based Options

Adding users

To log into a Samba share, a samba user is needed.

For Samba versions 3.4.0 and above: # pdbedit -a -u <user>

For earlier versions of Samba: # smbpasswd -a <user>

Existing smbpasswd databases can also be converted to the new format.

The user must already have an account on the server, if this is not the case, the following error will be displayed: Failed to modify password entry for user "<user>"

Add a new user to the Linux host with adduser. This article does not cover adding users to Windows systems.

Note: smbpasswd is no longer used by default as of Samba version 3.4.0

Web Based Option

SWAT: Samba web administration tool

SWAT is a facility that is part of the Samba suite. The main executable is called swat and is invoked by the eXtended InterNET Daemon, xinetd.

There are many and varied opinions regarding the usefulness of SWAT. No matter how hard one tries to produce the perfect configuration tool, it remains an object of personal taste. SWAT is a tool that allows Web-based configuration of Samba. It has a wizard that may help to get Samba configured quickly, it has context-sensitive help on each smb.conf parameter, it provides for monitoring of current state of connection information, and it allows network-wide MS Windows network password management.[1]

Note: An all-encompasing Webmin tool instead can also be used, and easily load the SWAT module there.
Warning: Before using SWAT, be warned that SWAT will completely replace 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.

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

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

Accessing shares

Shared resources from other computers on the LAN may be accessed and mounted locally by GUI or CLI methods The graphical manner is limited. Some Desktop Environments have a way to facilitate accessing these shared resources. However, most do not. In fact, most lightweight DE's and WM's offer no native method.

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.

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.

Accessing a Samba share from GNOME/Xfce4/LXDE

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

For access under Xfce4 using Thunar or LXDE using pcmanfm, one only needs gvfs-smb, available in the Official Repositories.

From a Nautilus/Thunar window, hit Template:Keypress or go to the "Go" menu and select "Location..." -- both actions will allow for the typing in the "Go to:" blank. Enter: smb://servername/share

Note: If the servername is not in /etc/hosts, use the IP address of the server in place of the servername.

From a Pcmanfm window, under the "Go" menu choose "Network Files".

Another GNOME browser program is Gnomba.

If iptables is running, the nf_conntrack_netbios_ns module should be loaded:

modprobe nf_conntrack_netbios_ns

Accessing shares from other graphical environments

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.

Other possible programs include pyneighborhood and RUmba, as well as the xffm-samba plugin for Xffm.

Accessing a Samba share from the shell

Shares may be accessed by using an automatic mounter or by using a manual method.

Automatic share mounting

There are several alternatives for easy share browsing.

  1. Install smbnetfs, available in the Official Repositories.
  2. Add the following line to /etc/fuse.conf:
  3. Load the fuse kernel module.
  4. Start the smbnetfs daemon:

If the required configuration is properly researched and done, it is claimed that all shares in the network are now automatically mounted under /mnt/smbnet.

Add the following to /etc/rc.conf to access the shares at boot:

MODULES=(... fuse ...)
DAEMONS=(... smbnetfs ...)

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

auth			"hostname" "username" "password"

Then, it may be necessary to change the permissions of /etc/smbnetfs/.smb/smbnetfs.conf and all include files for smbnetfs to work correctly:

# chmod 600 /etc/smbnetfs/.smb/smbnetfs.conf
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

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

Manual share mounting

1. Use smbclient to browse shares from the shell. To list any public shares on a server:

$ smbclient -L <hostname> -U%

2. Create the mount point for the share:

# mkdir /mnt/MOUNTPOINT

3. Mount the share using mount.cifs. Keep in mind that not all options may be needed nor desirable, such as password:

The Windows system's name
The shared directory
The local directory where the share will be mounted to
-o [options]
Specifies options for mount.cifs
Username used to mount the share
The shared directory's password
Used to specify the workgroup
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 //SERVER/SHARENAME/ will not work.

As CIFS refuses to mount 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 “wins” to the hosts line in /etc/nsswitch.conf may help. The corresponding /lib/ driver must also be present, which is provided by the samba (server) package.

4. To unmount the share, use:

# umount /mnt/MOUNTPOINT
Adding the share to fstab

Add the following to /etc/fstab for easy mounting:

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

The noauto option disables mounting it automatically at boot and noatime increases performance by skipping inode access times. However, the noatime is known to cause mount problems with kernel 3.4.x:

# mount error(22): Invalid argument
# Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)

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,noatime,credentials=/path/to/smdcredentials 0 0

The credentials file should contain the following text:


It is highly recommended to chmod 600 this file so that only the owning user can read and write to it.

If adding a Samba share to fstab, the netfs daemon should also be added to rc.conf, somewhere after the network daemon. The netfs daemon will mount network partitions at boot and, more importantly, unmount network partitions at shutdown. Even if using the noauto option in fstab, the netfs daemon should be used. Without it any network share that is mounted when shutting down will cause the network daemon to wait for the connection to time out, considerably extending poweroff time.

Allowing users to mount

Before enabling access to the mount commands, fstab needs to be modified. Add the users options to the entry in /etc/fstab:

//SERVER/SHARENAME /path/to/SHAREMOUNT cifs users,noauto,noatime,username=USER,password=PASSWORD,workgroup=WORKGROUP,ip=SERVERIP 0 0
Note: The option is users (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

Share files without a username and password

Option 1 - Force guest connections

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

security = user


security = share

Option 2 - Allow guest and User connections

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 =


interfaces = lo eth0
bind interfaces only = true

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

;   guest account = nobody

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

Sample configuration file

The configuration that worked for one user:

workgroup = WORKGROUP
server string = Samba Server
netbios name = PC_NAME
security = share
; the line below is important! If you have permission issues make
; sure the user here is the same as the user of the folder you
; want to share
guest account = mark
username map = /etc/samba/smbusers
name resolve order = hosts wins bcast
wins support = no
[public] comment = Public Share path = /path/to/public/share available = yes browsable = yes public = yes writable = no

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.

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 nmap and smbclient using pacman:

# pacman -S nmap smbclient

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 ( ) at 2005-02-15 11:45 PHT
Interesting ports on
(The 1661 ports scanned but not shown below are in state: closed)
139/tcp  open  netbios-ssn
5000/tcp open  UPnP

Interesting ports on
(The 1662 ports scanned but not shown below are in state: closed)
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 to check for NetBIOS names:

$ nmblookup -A
Looking up status of
        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
PRINTER$        Disk
PRINTER         Printer
IPC$            IPC       Remote Inter Process Communication

Server               Comment
---------            -------

Workgroup            Master
---------            -------
HOMENET               PUTER

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:


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/


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)

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.

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 /etc/samba/smb.conf:[2]

Note that this needs to be added to the local smb.conf, not to the server's smb.conf

# 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

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 /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[3] is to add this options to the smbfs/cifs mount options (in /etc/fstab for example):


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:


. /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
                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 /etc/samba/smb.conf as root and edit the section [global]:

  usershare allow guests = Yes
  usershare max shares = 100
  usershare owner only = False

close the file and do the following afterwards:

# mkdir /var/lib/samba/usershares
# chgrp users /var/lib/samba/usershares/
# chmod 1770 /var/lib/samba/usershares/

restart samba daemon

That's it! (solution was originally found here)

See also