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. This article provides instructions for users on how to setup Samba. It is strongly suggested that the user sticks close to the following directions.
- 1 Server configuration
- 2 Client configuration
- 3 Tips and tricks
- 4 Troubleshooting
- 4.1 Failed to start Samba SMB/CIFS server
- 4.2 Windows clients keep asking for password even if Samba shares are created with guest permissions
- 4.3 Windows 7 connectivity problems - mount error(12): cannot allocate memory
- 4.4 Trouble accessing a password-protected share from Windows
- 4.5 Getting a dialog box up takes a long time
- 4.6 Error: Failed to retrieve printer list: NT_STATUS_UNSUCCESSFUL
- 4.7 Sharing a folder fails
- 4.8 "Browsing" network fails with "Failed to retrieve share list from server"
- 4.9 You are not the owner of the folder
- 4.10 protocol negotiation failed: NT_STATUS_INVALID_NETWORK_RESPONSE
- 4.11 Connection to SERVER failed: (Error NT_STATUS_UNSUCCESSFUL)
- 4.12 Connection to SERVER failed: (Error NT_STATUS_CONNECTION_REFUSED)
- 5 See also
To share files with Samba, install the package.
The Samba server is configured in
/etc/samba/smb.conf.default. Copy the default Samba configuration file to
# cp /etc/samba/smb.conf.default /etc/samba/smb.conf
/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. There is also an on-line version available.
On Windows side, be sure to change
smb.conf to the in-use Windows Workgroup (default:
smbd.socketso the daemon is started on the first incoming connection. Do not forget to disable
"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
# mkdir -p /var/lib/samba/usershare
This makes the group sambashare:
# groupadd -r sambashare
This changes the owner of the directory and group you just created to root:
# 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 variables in
smb.conf configuration file:
... [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
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 pathes inside your home directory you must make it listable for the group others.
Adding a user
If it does not exist yet, create a Linux user account for the Samba user. Substitute
samba_user with your preferred name:
# useradd samba_user
Samba users use a password separate from that of the Linux user accounts. Create the Samba user account with the same name as in the previous command:
# pdbedit -a -u samba_user
Changing Samba user's password
To change a user's password, use
# smbpasswd samba_user
man smb.conf for details and explanation of configuration options. There is also an online version available.
[global] deadtime = 15 disable netbios = yes dns proxy = no hosts allow = 192.168.1. 127. 10. invalid users = nobody root load printers = no map to guest = Bad User max connections = 10 printing = bsd printcap name = /dev/null security = user server string = My Samba Server workgroup = WORKGROUP create mask = 0664 directory mask = 0775 force create mode = 0664 force directory mode = 0775 ;force group = +myusergroup [private] comment = Private Share path = /mnt/data read only = no valid users = myuser
nmb service(s) to apply configuration changes.
testparm validates the configuration of
# testparm -s
man smbclient for commonly used commands.
Shared resources from other computers on the LAN may be accessed and mounted locally by GUI or CLI methods. Depending on the desktop environment, GUI methods may not be available. See also #File manager configuration for use with a file manager.
There are two parts in sharing access. The first is the underlying file system mechanism, which some environments have built in. The second is the interface which allows the user to mount shared resources.
- After installing cifs-utils or smbclient, you must restart or modprobe cifs
- Otherwise mount fails with "cifs filesystem not supported by the system"
- If you have problems (a 3 min. timeout) while mounted a network share with cifs and doing a shutdown you could solve the problem with this description: WPA supplicant#Problem with mounted network shares (cifs) and shutdown (Date: 1st Oct. 2015)
For a lighter approach without support for listing public shares, only install
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.
# mount -t cifs //SERVER/sharename /mnt/mountpoint -o user=username,password=password,workgroup=workgroup,ip=serverip
- The Windows system name.
- The shared directory.
- The local directory where the share will be mounted.
man mount.cifsfor more information.
- 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.0for Windows Vista mount.
The simplest way to add an fstab entry is something like this:
//SERVER/sharename /mnt/mountpoint cifs username=username,password=password 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:
and the line in your fstab should look something like this:
//SERVER/SHARENAME /mnt/mountpoint cifs credentials=/path/to/credentials/sambacreds 0 0
If using systemd (modern installations), one can utilize the
x-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
gidoptions may cause input ouput errors in programs that try to fetch data from network drives.
//SERVER/SHARENAME /mnt/mountpoint cifs credentials=/path/to/smbcredentials,x-systemd.automount,uid=username,gid=usergroup 0 0
\040(ASCII code for space in octal). For example,
//SERVER/share nameon the command line should be
//SERVER/SHARENAME /mnt/mountpoint cifs users,credentials=/path/to/smbcredentials,workgroup=workgroup,ip=serverip 0 0
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.
WINS host names
Thepackage provides a driver to resolve host names using WINS. To enable it, add “wins” to the “hosts” line in /etc/nsswitch.conf.
There are several ways to easily browse shared resources:
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
domain master = auto
If everything works as expected, install from the official repositories.
Then, add the following line to
and load the
fuse kernel module:
# modprobe fuse
Now copy the directory
/etc/smbnetfs/.smb to your home directory:
$ cp -a /etc/smbnetfs/.smb ~
Then create a link to
$ 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
to include one or more entries like this:
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
If you are using the Dolphin or Nautilus file managers, 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:
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
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
Then, you can start and/or enable the
smbnetfs daemon as usual. The system-wide mount point is at
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 official repositories.package, available in the
Ctrl+l and enter
smb://servername/share in the location bar to access your share.
The mounted share is likely to be present at
~/.gvfs in the filesystem.
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 thepackage from the official repositories.
If when navigating with Dolphin you get a "Time Out" Error, you should uncomment and edit this 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.
- 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
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
... [myshare] comment = Private path = /mnt/data read only = no veto files = /*.exe/*.com/*.dll/*.bat/*.vbs/*.tmp/*.mp3/*.avi/*.mp4/*.wmv/*.wma/
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 pacman:and using
# pacman -S nmap smbclient
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 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.
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
Failed to start Samba SMB/CIFS server
Check if the permissions are set correctly for
/var/cache/samba/ and restart the
# chmod 0755 /var/cache/samba/msg
map to guest inside the
global section of
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
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.
For trouble accessing a password protected share from Windows, try adding this to
[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
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
load printers = No printing = bsd printcap name = /dev/null disable spoolss = Yes
Restart the samba service,
smbd.service, and then check your logs:
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.
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.
You are not the owner of the folder
Simply try to reboot the system.
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
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.