Samba

From ArchWiki
Revision as of 15:14, 16 September 2011 by Gladstone (Talk | contribs) (Starting and automating the daemons: -- Rewrite (using SSH entry as a template) as FAM is deprecated)

Jump to: navigation, search

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.


Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어


External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

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

Installing only the client program is sufficient for systems that are not meant to share files, only access them:

# pacman -S smbclient

In order to make shares available to clients, install the Samba server package (which includes Template:Codeline):

# pacman -S samba

Configuration

The Template:Filename file must be created before starting the daemons. Once that is set up, users may opt for using an advanced configuration interface like SWAT.

smb.conf

As root, copy the default Samba configuration file to Template:Filename:

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

Open Template:Filename and edit it to suit your needs. 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 Template:Codeline

Managing the samba daemon

To automatically start Template:Codeline at boot, add it to the DAEMONS line in Template:Filename:

DAEMONS=(... ... samba ... ...)

To start/restart/stop the daemon manually, use the following:

# rc.d {start|stop|restart} samba

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 Template:Filename parameter, it provides for monitoring of current state of connection information, and it allows network-wide MS Windows network password management.[1]

Note: If you have problems with these directions, you can use the more all-encompasing Webmin tool instead, and easily load the SWAT module there.
Warning: Before using SWAT, please be warned SWAT will completely replace your Template:Filename with a fully optimized file that has been stripped of all comments you might have placed there, and only non-default settings will be written to the file.

To use SWAT, first install xinetd:

# pacman -S xinetd

Edit Template:Filename using your favorite text editor. To enable SWAT, change the Template:Codeline line to Template:Codeline.

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 you can add an entry for swat to Template:Filename and omit the first 3 lines of the configuration.

Then start xinetd daemon:

# rc.d start xinetd

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

http://localhost:901/

Adding users

To log into a Samba share you will need to add a user.

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 a account on the server. If the user does not exist you will receive the error:

Failed to modify password entry for user "<user>"

You can 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

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 you are using KDE, it has the ability to browse Samba shares. You therefore do not need any additional packages. (However, for a GUI in the KDE System Settings you have to install the kdenetwork-filesharing package from [extra]. Another program choice is SMB4K.) If, however, you plan to use the share in Gnome or solely from a shell, you will need an additional package.

Accessing a Samba share from Gnome/Xfce4

In order to access samba shares through Nautilus, first install the gvfs-smb and gnome-vfs packages:

# pacman -S gvfs-smb gnome-vfs

For access under Xfce4 using thunar, one only needs gvfs-smb

# pacman -S gvfs-smb

From a Nautilus/Thunar window, hit Template:Keypress+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 Template:Filename, use the IP Address of the server in place of the servername.

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.

smbnetfs

1. Install Template:Package Official:

# pacman -S smbnetfs

2. Add the following line to Template:Filename:

user_allow_other

3. Load the Template:Codeline kernel module:

# modprobe fuse

4. Start the Template:Codeline daemon:

# /etc/rc.d/smbnetfs start

If the required configuration is properly researched and done, it is claimed that all shares in the network are now automatically mounted under Template:Filename.

Add the following to Template:Filename 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, you have to edit Template:Filename by uncommenting the line starting with "auth" and editing it to your needs:

auth			"hostname" "username" "password"

Then, it may be necessary to change the permissions of Template:Filename and all include files for smbnetfs to work correctly:

# chmod 600 /etc/smbnetfs/.smb/smbnetfs.conf
fusesmb
Note: Because Template:Codeline is malfunctioning with Template:Codeline, revert to using older versions if necessary. See the relevant forum topic for details.

1. Install the Template:Package AUR package from the AUR.

2. Create a mount point:

# mkdir /mnt/fusesmb

3. Load Template:Codeline module:

# modprobe fuse

4. Mount the shares:

# fusesmb -o allow_other /mnt/fusesmb

For mounting shares at boot, add the command above to Template:Filename and add Template:Codeline module to Template:Filename:

MODULES=(... fuse ...)
Autofs

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 Template:Codeline. Keep in mind that not all options may be needed nor desirable, such as Template:Codeline:

# mount -t cifs //SERVER/SHARENAME MOUNTPOINT -o user=USERNAME,password=PASSWORD,workgroup=WORKGROUP,ip=SERVERIP
Template:Codeline
The Windows system's name
Template:Codeline
The shared directory
Template:Codeline
The local directory where the share will be mounted to
Template:Codeline
Specifies options for Template:Codeline
Template:Codeline
Username used to mount the share
Template:Codeline
The shared directory's password
Template:Codeline
Used to specify the workgroup
Template:Codeline
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 Template:Filename will not work.

4. To unmount the share, use:

# umount /mnt/MOUNTPOINT
Adding the share to Template:Filename

Add the following to Template:Filename for easy mounting:

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

The Template:Codeline option disables mounting it automatically at boot and Template:Codeline increases performance by skipping inode access times.

After adding the previous line, the syntax to mount files becomes simpler:

# mount /mnt/MOUNTPOINT

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

Allowing users to mount

Before enabling access to the mount commands, Template:Filename needs to be modified. Add the Template:Codeline options to the entry in Template:Filename:

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

Option 1 - Force guest connections

Edit Template:Filename and change the following line:

security = user

to

security = share

Option 2 - Allow guest and User connections

Edit Template:Filename and add the following line:

map to guest = Bad User

After this line

security = user


If you want to 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

(changing eth0 to the local network you want share with.)

If you want to 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:

[global]
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 Template:Package Official and Template:Package Official using pacman:

# pacman -S nmap smbclient

2. Template:Codeline 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: Template:Command

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 Template:Codeline to check for NetBIOS names: Template:Command

Regardless of the output, look for <20>, which shows the host with open services.

4. Use Template:Codeline to list which services are shared on PUTER. If prompted for a password, pressing enter should still display the list: Template:Command

This shows which folders are shared and can be mounted locally. See: #Accessing Samba shares

Remote control of Windows computer

Samba offers a set of tools for communication with Windows. These can be handy in case you cannot access a Windows computer through remote desktop, as shown by some examples.

Send shutdown command with a comment:

$ net rpc shutdown -C "comment" -I IPADDRESS -U USERNAME%PASSWORD

If you prefer a forced shutdown instead change -C with comment to a single -f. For a restart you 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

Troubleshooting

Trouble accessing a password-protected share from Windows

If you are having trouble accessing a password protected share from Windows, try adding this to Template:Filename:[2]

Note that you have to add this to your 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

I do not have any printer connected to this server, so I added this to the global section:

load printers = no
printing = bsd
disable spoolss = yes
printcap name = /dev/null

Not sure if all of them are necessary, but at least it works now.

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!

If you would like to stick to the 'smbpasswd' backend try changing this in Template:Filename:

passdb backend = smbpasswd

or convert your smbpasswd entries using:

sudo pdbedit -i smbpasswd -e tdbsam


Error: Value too large for defined data type

With some applications you could get 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 your 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 starting your computer, the samba shares you have defined cannot be accessed from any client, check the following :

  • Make sure that you have not forgotten to add the samba daemon 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.

Resources