From LQWiki
This article deals with setting up Samba as a server.
Contents |
Samba Server
Be aware that Windows networking isn't a clean and simple system, and that Microsoft has modified the behaviour of Windows networking (known as SMB or CIFS) with each version of Windows and even between Service Packs. This has caused interoperability problems, but the main difficulty is that you may have to spend a bit of time learning how SMB works in order to resolve a problem.
Several Linux distributions now supply their own tools for configuring Samba in a simple way, and these are mentioned below. Samba itself also includes a basic Web-based configuration system called SWAT, which is often provided in a separate package to the Samba server and client software. Once installed, it listens on port 901, so you can access it by typing the URI in your Web browser:
For more complex LAN configurations you can avoid most problems by reading the SAMBA-HOWTO, which is supplied with Samba, and is also available from the project Website:
As well as the main HOWTO, the Samba documentation includes a large collection of notes, more specific HOWTOs and a HTML copy of the excellent (but now obsolete) Using Samba book from O'Reilly. If you have installed the Samba documentation package you will find these in /usr/share/doc/samba-doc-<version>.
Another web-based configuration tool is contained in webmin.
For details on connecting to Windows servers, see the Samba page.
Debian
Installing samba on a debian system is very simple, thanks to a program called Aptitude. Simply open up a shell (command prompt) and type in:
apt-get install samba
It will ask you some basic questions about how to configure the server--most of the relevant information is found below. Also, don't get too scared, you may edit all of the options later in the /etc/samba/smb.conf file.
For a more in depth look at installing samba on a debian system, try :
- Samba Server Setup in Debian (www.debianhelp.co.uk)
Fedora
Fedora has a GUI-utility system-config-network that provides basic access to samba-configuration. Make sure that firewall rules do not disable samba traffic.
Mandriva
excecute (as root):
urpmi drakwizard drakwizard
select samba
Also, ksambaplugin is available in contribs for Mandrake from 9.1 onwards, and provides probably the best tool for configuring samba. For more information on configuring samba for Mandriva Linux, please see the Mandriva KnowledgeBase
SUSE
Change your user to root:
sux -
Run
yast2 samba-server
There should be details at /usr/share/doc/packages/samba/examples/smb.conf.SuSE
Red Hat
There are three ways to configure the samba daemon in Red Hat Linux 9. "redhat-config-samba" is a graphical configuration client that is available (in Gnome) under hat|System Settings|Server Settings|Samba. SWAT, a browser based configuration utility can be installed. And lastly the /etc/samba/smb.conf can be edited by hand.
Configuring Samba (smb.conf)
The most important part of configuring samba to work on your network is proper configuration of the smb.conf file. On most systems this is found in /etc/samba/smb.conf. Simply open it up in a text editor of your choice like so:
pico /etc/samba/smb.conf
Now you see something like the following:
[global] ... [homes] ... [tmp] ...
The smb.conf file is seperated into sections, or shares. The main section is called [global] and the settings found in it are dispersed though EVERY samba share. However, each setting can be overridden by setting the option in each individual share, i.e. all shares start with the settings found in the [global] section, but changes to, say, the [home] shares' settings will change only the [home] shares.
Try to keep each section as simple as possible, there is no need to overload samba with 20 options.
Now, onto what the options are. An extensive guide may be found by simply typing in "man smb.conf" at the command prompt, but this wiki will try to keep it as simple as possible.
The Global Section
This section describes how access should be given to each of the shares, what workgroup the server is a part of, etc.
[global] ;This must be in the same workgroup as the computers trying to access the share workgroup = MDKGROUP ;This is the default and should be kept. ;it gets past many nasty annoyances Windows machine's may provide. encrypt passwords = yes ;Keeping security = user is highly recommended! It means that each user MUST ;provide a username/password to access the shares (unless overridden in a particular ;share). However, each user must be a user on the server. You can easily add ;users with the adduser command. security = user ;Another way to provide access, but much less secure and not recommended. ;security = share ;You now need to supply it with a password backend ;(a place to store usernames/passwords). ;It is recommended that you use smbpasswd, though larger networks may require ;tbdsam. Smbpasswd works similarly to passwd, you may add ;usernames, passwords, etc. ;Remember, however, using security = user means you must have unix accounts ;for each user! passwd backend = smbpasswd ;passwd backend = tbdsam ;This last option lets you have a guest account that may access the shares. ;passwd backend = smbpasswd guest
The Home Section
Upon connecting to the server, each user may get a [home] share.
[home]
;Just a description
comment = Home Directories
;Set browseable to yes if you want the share to show up with tools like
;net view or smbclient.
browseable = no
read only = no
Connecting to shares from Windows
You can connect your Linux/Samba shares from Network Neighbourhood or map them to a drive from Windows Explorer.
Mapping shares from the command line
Here's an example how to connect to a Samba disk share from Windows. This batch script works with Windows 98/2000/XP. Simply open up notepad, paste this text into the file, and save it as something like, "connect.bat." Be sure not to forget the ".bat" or the script will not work. After that, replace "\\yourServer\share /user:username" with the appropriate names. It will reconnect the share upon startup each time.
@echo off echo Connection Script.... echo ------------------------------------------ echo . echo Disconnecting network share...(Z:) net use /delete z: echo Reconnecting network share...(Z:) echo Please enter password if prompted echo . net use z: \\yourServer\share /user:username echo . echo Script completed... pause
Here's a second script, this one written in VBScript, so it will only work on Windows 98SE/2000/XP. It is, however, much more reliable, a bit of fault tolerance built in to it. Once again, just change the appropriate names.
dim wshNetwork
on error resume next
set wshNetwork = CreateObject("WScript.Network")
wshNetwork.MapNetworkDrive "Z:", "\\yourServer\share"
if Err.number <> 0 then
wscript.echo "Couldn't connect, sorry " & wshNetwork.userName
end if
Tips for using Samba with Windows 98
When using older versions of Samba (prior to version 4), configuring Windows to use plain text passwords removes many problems, and if run on a LAN it poses less of a security risk. Reg file provided here
REGEDIT4
[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\VNETSUP] "EnablePlainTextPassword"=dword:00000001
Tips for using Samba with Windows 2000
- link title (www.example.com)
Checking Shares
An easy way to check if your Samba shares are working properly is to use the smbclient tool in Linux and the net command in Windows (to install smbclient in debian, simply type "apt-get install smbclient"). For instance, to view all of the available share information in Linux, simply type:
smbclient -L hostname
This is analogous to the following command on a Windows machine:
net view \\hostname
Where hostname can be any host on the network, even localhost. You can also provide a username to smbclient, like so:
smbclient -L hostname -U username
It will then prompt you for a password, you can enter none for anonymous access.
Firewall Configuration
The following should apply to most (if not all) Linux distributions, and is an easily forgotten part of Samba configuration. If your samba shares do not show up in windows network environment the firewall configuration is one of the probable causes.
The following ports will need to be allowed through your firewall to enable Windows to connect to the Linux Samba server. It follows a format of Port Number:Protocol.
445:tcp 139:tcp 138:udp 137:udp
See www.iana.org for a list of common port numbers, names and their protocols.

This page is available under a