December 4, 2003

Fast start with Samba

Author: JT Smith

When we first asked for suggestions for inclusion in the Samba HOWTO documentation, someone wrote asking for example configurations -- and lots of them. This article offers extensive descriptions of Samba configuration possibilities.
This article is excerpted from the recently published book The Official Samba-3 HOWTO and Reference Guide.

Samba needs very little configuration to create a basic working system. These examples have been obtained from a number of people who made requests for example configurations. All identities have been obscured to protect the guilty and any resemblance to unreal non-existent sites is deliberate.

The configuration examples are designed to cover everything necessary to get Samba running. They do not cover basic operating system platform configuration, which is clearly beyond the scope of this text. We also assume that Samba has been correctly installed.

We'll start by configuring a Stand-alone Server, by which we mean no more than the fact that it is not a Domain Controller and it does not participate in Domain Control. It can be a simple workgroup-like server, or it may be a complex server that is a member of a domain security context.

Annonymous Read-Only Document Server

The purpose of this type of server is to make available to any user any documents or files that are placed on the shared resource. The shared resource could be a CD-ROM drive, a CD-ROM image, or a file storage area. The file system share point will be /export, and all files will be owned by a user called Jack Baumbach. Jack's login name will be jackb. His password will be m0r3pa1n -- of course, that's just the example we are using; do not use this in a production environment because all readers of this document will know it.

Installation Procedure -- Read-Only Server

1. Add user to system (with creation of the users' home directory):

root# useradd -c "Jack Baumbach" -m -g users -p m0r3pa1n jackb

2. Create directory, and set permissions and ownership:

root# mkdir /export
root# chmod u+rwx,g+rx,o+rx /export 
root# chown jackb.users /export

3. Copy the files that should be shared to the /export directory.

4. Install the Samba configuration file (/etc/samba/smb.conf) as shown below:

[global]
workgroup = MIDEARTH 
netbios name = HOBBIT 
security = share

[data]
comment = Data 
path = /export 
read only = No 
guest only = Yes

5. Test the configuration file:

root# testparm

Note any error messages that might be produced. Do not proceed until you obtain error-free output. An example of the output with the following file will list the file.

Load smb config files from /etc/samba/smb.conf Processing section "[data]"
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions [Press enter]

[global]
workgroup = MIDEARTH
netbios name = HOBBIT
security = share

[data]
comment = Data
path = /export
read only = No
guest only = Yes

6. Start Samba using the method applicable to your operating system platform.

7. Configure your Microsoft Windows client for workgroup MIDEARTH, set the machine name to ROBBINS, reboot, wait two to five minutes, then open Windows Explorer and visit the Network Neighborhood. The machine HOBBIT should be visible. When you click this machine icon, it should open up to reveal the data share. After clicking the share it, it should open up to revel the files previously placed in the /export directory.

Anonymous Read-Write Document Server

We should view this configuration as a progression from the previous example. The difference is that shared access is now forced to the user identity of jackb and to the primary group jackb belongs to. One other refinement we can make is to add the user jackb to the smbpasswd file. To do this, execute:

root# smbpasswd -a jackb
New SMB password: m0r3pa1n
Retype new SMB password: m0r3pa1n Added user jackb.

Addition of this user to the smbpasswd file allows all files to be displayed in the Explorer Properties boxes as belonging to jackb instead of to User Unknown.

The complete, modified smb.conf file is as shown below:

[global]
workgroup = MIDEARTH 
netbios name = HOBBIT 
security = SHARE

[data]
comment = Data 
path = /export 
force user = jackb 
force group = users 
read only = No 
guest ok = Yes

Anonymous Print Server

An anonymous print server serves two purposes: It allows printing to all printers from a single location, and it reduces network traffic congestion due to many users trying to access a limited number of printers.

In the simplest of anonymous print servers, it is common to require the installation of the correct printer drivers on the Windows workstation. In this case the print server will be designed to just pass print jobs through to the spooler, and the spooler should be configured to do raw passthrough to the printer. In other words, the print spooler should not filter or process the data stream being passed to the printer.

In this configuration it is undesirable to present the Add Printer Wizard and we do not want to have automatic driver download, so we will disable it in the following configuration:

[global]
workgroup = MIDEARTH 
netbios name = LUTHIEN 
security = share 
printcap name = cups 
disable spoolss = Yes 
show add printer wizard printing = cups

[printers]
comment = All Printers 
path = /var/spool/samba 
guest ok = Yes 
printable = Yes 
use client driver = Yes 
browseable = No

This configuration is not ideal. It uses no smart features, and it deliberately presents a less than elegant solution. But it is basic, and it does print.

Note: Windows users will need to install a local printer and then change the print to device after installation of the drivers. The print to device can then be set to the network printer on this machine.
Make sure that the directory /var/spool/samba is capable of being used as intended. The directory must be owned by the superuser (root) user and group, and directory permissions should be set for public read-write with the sticky-bit set:

root# chown root.root /var/spool/samba
root# chmod a+rwtx /var/spool/samba

Note: On CUPS enabled systems there is a facility to pass raw data directly to the printer without intermediate processing via CUPS print filters. Where use of this mode of operation is desired it is necessary to configure a raw printing device. It is also necessary to enable the raw mime handler in the /etc/mime.conv and /etc/mime.types files.

File and Print Server, Secure Read-Write

We progress now from simple systems to a server that is slightly more complex. In this hypothetical environment, the site is demanding a simple environment that is secure enough but not too difficult to use.

Our new server requires a public data storage area in which only authenticated users (i.e., those with a local account) can store files, as well as a home directory. There will be one printer that should be available for everyone to use.

Site users will be Jack Baumbach, Mary Orville, and Amed Sehkah. Each will have a password (not shown in further examples). Mary will be the printer administrator and will own all files in the public share.

This configuration will be based on default User Level Security, and for which the default is to store Microsoft Windows-compatible encrypted passwords in a file called /etc/samba/smbpasswd. The default smb.conf entry that makes this happen is: passdb backend = smbpasswd, guest. Since this is the default it is not necessary to enter it into the configuration file. Note that guest backend is added to the list of active passdb backends not matter was it specified directly in Samba configuration file or not.

1. Add all users to the operating system:

root# useradd -c "Jack Baumbach" -m -g users -p m0r3pa1n jackb 
root# useradd -c "Mary Orville" -m -g users -p secret maryo 
root# useradd -c "Amed Sehkah" -m -g users -p secret ameds

2. Configure the Samba smb.conf file as shown:

[global]
workgroup = MIDEARTH
netbios name = OLORIN
printcap name = cups 
disable spoolss = Yes
show add printer wizard = No 
printing = cups

[homes]
comment = Home Directories 
valid users = %S 
read only = No 
browseable = No

[public]
comment = Data 
path = /export 
force user = maryo 
force group = users 
guest ok = Yes

[printers]
comment = All Printers 
path = /var/spool/samba 
printer admin = root, maryo 
create mask = 0600 
guest ok = Yes 
printable = Yes 
use client driver = Yes 
browseable = No

3. Initialize the Microsoft Windows password database with the new users:

root# smbpasswd -a root
New SMB password: bigsecret
Reenter smb password: bigsecret
Added user root.

root# smbpasswd -a jackb
New SMB password: m0r3pa1n
Retype new SMB password: m0r3pa1n
Added user jackb.

root# smbpasswd -a maryo
New SMB password: secret
Reenter smb password: secret
Added user maryo.

root# smbpasswd -a ameds
New SMB password: mysecret
Reenter smb password: mysecret
Added user ameds.

4. Install printer using the CUPS Web interface. Make certain that all printers that will be shared with Microsoft Windows clients are installed as raw printing devices.

5. Start Samba using the operating system administrative interface, or manually by running root# nmbd; smbd;

6. Configure the /export directory:

root# mkdir /export
root# chown maryo.users /export
root# chmod u=rwx,g=rwx,o-rwx /export

7. Check that Samba is running correctly:

root# smbclient -L localhost -U% 
Domain=[MIDEARTH] OS=[UNIX] Server=[Samba-3.0.0]

Sharename	Type	Comment
---------	----	-------

public		Disk	Data
IPC$		IPC	IPC Service (Samba-3.0.0)
ADMIN$		IPC	IPC Service (Samba-3.0.0)
hplj4		Printer	hplj4

Server	Comment
------	-------
OLORIN	Samba-3.0.0

Workgroup	Master
---------	------
MIDEARTH	OLORIN

8. Connect to OLORIN as maryo:

root# smbclient //olorin/maryo -Umaryo%secret
OS=[UNIX] Server=[Samba-3.0.0]
smb: \> dir

. D 0 Sat Jun 21 10:58:16 2003
.. D 0 Sat Jun 21 10:54:32 2003
Documents D 0 Fri Apr 25 13:23:58 2003
DOCWORK D 0 Sat Jun 14 15:40:34 2003
OpenOffice.org D 0 Fri Apr 25 13:55:16 2003
.bashrc H 1286 Fri Apr 25 13:23:58 2003
.netscape6 DH 0 Fri Apr 25 13:55:13 2003
.mozilla DH 0 Wed Mar 5 11:50:50 2003
.kermrc H 164 Fri Apr 25 13:23:58 2003
.acrobat DH 0 Fri Apr 25 15:41:02 2003
55817 blocks of size 524288. 34725 blocks available
smb: \> q

By now you should be getting the hang of configuration basics. To explore more complex examples, refer to the book from which this article is excerpted.

Click Here!