Revision as of 12:00, 21 January 2013

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.

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>

The user must already have a Linux user account on the server, if this is not the case, the following error will be displayed: Failed to add entry for user <user>.

Note: smbpasswd is no longer used by default as of Samba version 3.4.0 but existing smbpasswd databases can be 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 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.

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.

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.

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.

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/libnss_wins.so driver must also be present, which is provided by the samba (server) package.

It is highly recommended to chmod 600 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:

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

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.

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.

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:

Troubleshooting

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:

Changes in Samba version 3.4.0

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[2] 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)

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: