Step
1: Where do I get Samba?
Samba
is a great tool for letting Microsoft Windows users
share hard drives and printers with Linux users. With
the recent release of Samba 2.2, the Samba team has
made major improvements to their server software,
including support for Windows 2000 and NT 4.0 clients.
In addition, Samba 2.2 now can be configured as a
Windows NT Primary Domain Controller. In the coming
series of tips, we're going to show you how to get
started using Samba 2.2.
First,
you'll need to know where to get it.
Most
Linux distributions come with a version of Samba on
their distribution CDs. If you can't find a copy of
Samba on your distribution of Linux, download it from
the Samba web site.
http://www.samba.org
Step
2: Installing Samba
You
can install Samba one of two ways. Both ways depend
on the type of file you download from the Samba web
site. If you download a binary package for your distribution,
make sure to familiarize yourself with where the various
Samba files are installed. For example, if you install
the Red Hat RPM for Samba 2.2, your configuration
files will be installed in the /etc/samba/ directory.
If
you download the Samba source files and compile it
on your Linux system, Samba will install in the /usr/local/samba
directory. The configuration files will be in the
/usr/local/samba/conf/ and the executable files will
be in the /usr/local/samba/bin directory
The
all-important configuration file for Samba is named
smb.conf. If you're not sure where this file is on
your system, just use the find command below to find
where it is. Make sure that you have superuser privileges
when you run it in a terminal window.
find
/ -name smb.conf -print
For
those of you that have locate installed on your system,
the command "locate smb.conf" will also
work just fine.
Step
3: Getting familiar with smb.conf
Open
the smb.conf file in your favorite text editor to
make configuration changes. Although there are some
graphic interfaces that you can use to configure Samba,
you should familiarize yourself with the configuration
file smb.conf when configuring Samba for the first
time.
You'll
notice that there are two types of comment lines in
the smb.conf file. Any line that begins with a "#"
or a ";" is not recognized by the Samba
server daemon. For lines that describe or define a
particular setting in the configuration file, you'll
see that the line begins with a "#". Lines
that begin with ";" are usually valid configuration
settings that aren't currently being used.
The
smb.conf file is broken down into 2 sections: the
Global Settings and the Share Definitions. First,
we'll make some changes to the Global Settings.
Step
4: smb.conf Global Settings
At
the top of the smb.conf file, you'll find the section
labeled Global Settings. First, you'll want to edit
these settings at the top of the Global Settings
# workgroup = NT-Domain-Name or Workgroup-Name
workgroup = MYGROUP
#
server string is the equivalent of the NT Description
field
server string = Server description
The
workgroup setting is for configuring the NT Domain
or Windows Workgroup that your Samba server will be
included in when you browse your Windows Network Neighborhood.
If you're configuring Samba for your home network,
the workgroup MYGROUP should work just fine.
It
should be noted that if you intend to share network
devices on your Linux machine from Windows, you'll
need to configure your Windows machine for "Client
for Microsoft Networks" in your Network Neighborhood
properties. This is not the default setting for many
consumer Windows systems.
The
server string setting will be the description of the
server when you browse it in the Windows Network Neighborhood.
This can be set to anything you like, but it's useful
for beginners to use this setting to identify the
server. For example, setting the server string to
Samba 2.2 Server will make it easy to find from Windows.
Step
5: More Global settings in smb.conf
The
fastest way to configure Samba to share a Linux drive
with a Windows user is to create a login on both systems
with identical login names. This will become clearer
when we talk about Share Definitions. For now, we
need to talk a little bit about passwords.
In
your text editor, skip down to the setting in your
smb.conf file that reads
# You may wish to use password encryption. Please
read
# ENCRYPTION.txt, Win95.txt and WinNT.txt in the Samba
documentation.
# Do not enable this option unless you have read those
documents
; encrypt passwords = yes
; smb passwd file = /etc/samba/smbpasswd
Remove
the two semi-colons from the bottom two lines if you're
going to connect to Samba from Windows 98/NT/2000/
or ME. If you're connecting from Windows 95, you don't
have to edit these two settings.
By
default, Samba uses plain text passwords. This was
fine when Windows 95 was the predominant end-user
operating system for shared Windows machines because
Windows 95 also used plain text passwords. Later versions
of Windows use encrypted passwords. Rather than doing
some nifty Windows registry editing to work around
this problem, turn on Samba's encrypted passwords
by uncommenting these two lines.
Once
you've removed these semi-colons, you can then skip
down to the Share Definitions section of your smb.conf
file.
Step
6: Share Definitions
By
default, your smb.conf file sets up Linux user home
directories to share with Windows machine logins with
the same user name. At the top of the Share Definitions
section of your smb.conf file, you should see these
settings
[homes]
comment = Home Directories
browseable = no
writable = yes
Change
the browseable setting to "yes" to enable
browsing of the user's home directory from a Windows
machine. Once you've changed this, save your changes
to smb.conf and exit your text editor. Now you just
have to create a Samba user password for your share.
Step
7: Setting your Samba user password
If
you configured Samba for encrypted passwords as we
did earlier (Step 5), you'll need to add a user to
your smbpasswd file. The username should match your
Windows login name and password (case-sensitive).
To add a user to the smbpasswd file, you'll need to
use the smbpasswd command. If you installed Samba
from a binary package, you can simply run the command
smbpasswd
-a username
in
a terminal window as the superuser root. If you installed
Samba from source, run the same command in your /usr/local/samba/bin/
directory with a "./" in front of the command.
you'll be prompted for a password for the user you're
creating. Enter the password that you use under Windows
for the username you're adding.
That's
all you need to do for configuring Samba to share
a drive with your Windows network computer. Of course,
you'll need to run the Samba server first.
Step
8: Running the Samba server daemon
Using
our quick configuration for sharing a Linux drive,
all you need to do now is run the Samba server daemon
on your Linux machine to enable the shared drive.
Once again, your installation choice will determine
where you can run the server daemon executable. Binary
install users should look for the smb script created
in your /etc/rc.d/init.d or /etc/init.d. Simply run
the script as the superuser root with the command
./smb
start
If
you installed from source, you can run the server
daemons smbd and nmbd from the /usr/local/samba/bin
directory with the commands
./smbd
-D ./nmbd -D
This
starts the Samba server. So why the two commands?
Well, if you really must know - read the next step.
Step
9: The server daemons smbd and nmbd
For
those of you who just have to know why Samba has two
server daemons, the answer is simple. Networks can
be complex. Each server daemon allows the use of a
different network service for sharing devices over
a network. By using both server daemons, you provide
services for all types of Windows machines.
The
smbd server daemon provides the file and print services
to SMB clients, such as Windows 95/98, Windows NT,
Windows for Workgroups. SMB stands for "Server
Message Block" and is defined as a network protocol
for sharing files, printers, serial ports, and communications
abstractions such as named pipes and mail slots between
computers.
The
nmbd server daemon allows for NetBIOS over IP name
service requests over a network, like those produced
by SMB/CIFS clients such as Windows 95/98/ME, Windows
NT and Windows 2000.
If
you don't care about this stuff and just want to get
your Samba share working, not to worry. We're almost
there.
Step
10: Sharing a device from Windows
Once
you've run the Samba server daemons on your Linux
machine, you should be able to login on your networked
Windows machine and see the Linux computer name in
your Network Neighborhood. (Remember, you should have
the same username and password on both the Linux and
Windows machine.) If you do see the Linux computer
name there, open Windows Explorer (not Internet Explorer)
and open the Tools menu. Select the Map Network Drive
option. This will open a dialog box for your share
definition.
Choose
the drive letter you want the network drive to use
(E:, F:, etc.) and then type in the Path to the shared
drive. This should look like this
LINUXCOMPUTERNAMEUSERNAME
The
LINUXCOMPTERNAME should be the name of the Linux computer
as it appears on the network and the USERNAME should
be your username. It might take a moment or two, but
you should then see the new drive letter in Windows
Explorer with the home directory of your username
on the Linux machine shared.
Step
11: Where to look when things don't work
It
never fails. You follow the directions to perfection
and the darn thing doesn't work. This tip is for those
who've followed our directions for configuring Samba
for a simple share and it didn't work.
First,
if you can't map the network drive with Windows, go
to your Linux machine and open a terminal window.
Change users to the superuser root with the su command.
Remembering how you installed Samba and change directories
to the /usr/local/samba/bin/ directory (if you installed
from source) or the /usr/bin/ directory. Run the program
./testparm
This
program will read your smb.conf file and tell you
if there are any settings configured incorrectly.
If you find no errors there, check your Samba log
files. On most systems, the Samba log files will be
kept in the /var/log/samba/ directory. The log files
will be named log.smbd and log.nmbd. Check both of
them for any errors.
Last
but not least, check your Linux system logs in the
file /var/log/messages. You may see smbd or nmbd errors
here as well.
Step
12: Using a Windows printer from Linux
Well,
now that you've tested your knowledge of Samba, perhaps
you're ready to take on a different problem. In the
next few steps, we'll show you how to use a Windows
shared printer from your Linux machine.
The
first thing to do to use a Windows printer is to make
sure that the printer is an actual network shared
device in Windows. If it's not, you won't be able
to use the printer from Linux at all.
On
your Windows computer, open your Settings menu from
the Start menu. Select Printers to list the printers
configured on your system. When you see your printer
in the window that opens, right-click the printer's
icon and select Sharing from the menu. This will bring
up a dialog box with two radio buttons and three data
entry fields. Make sure that the Shared radio button
is selected and take note of the printer name in the
first data entry field. If the printer doesn't have
a name, enter a name in the first field and write
it down.
That's
basically all the preparation you need on the Windows
side. Now that you know that the Windows printer is
shared, you're ready to tackle the Linux configuration
to use it.
Step
13: Configuring Linux to use a Windows printer
The
first step in configuring your Linux system to use
a Windows shared printer is to create an entry in
your /etc/printcap file. If you've never used a printer
on your Linux system, this file should be empty.
There
are two ways to go about adding a printer device to
your Linux system. You can edit the file manually
and add a printer to your configuration or you can
use a program that helps you configure it. If you've
never done this before, we recommend you use a utility
program to help you. The syntax for the /etc/printcap
file can be a little tricky if you've never seen it
before. In this case, we'll use the Red Hat printtool
utility. you'll need to run printtool in a terminal
window with X running.
When
you open the printtool utility, select the Add button
to add your Windows printer. From the menu that appears,
select the radio button that says "SMB/Windows
95/NT Printer" and click OK. Now you should see
the Printer Entry dialog box. The first three fields
in the form will be filled out for you with these
settings
Names: lp
Spool Directory: /var/spool/lpd/lp
File Limit in Kb (0 = no limit): 0
You
can't leave these as they are. you'll need to fill
in at least three on the fields that are left. First,
enter the name of the Windows machine in the Hostname
of Printer Server field. If you use IP addresses on
your network, you can enter the IP address of you
Windows machine in the IP number of Server field.
This field is optional. Only use it if you know the
IP number. Enter the name of the printer as it was
listed in the Share menu on the Windows machine in
the Printer Name field. If the printer name was in
all capital letters, be sure that you enter it here
the same way.
The
last thing you should do is select a printer filter.
Step
14: Selecting a Printer Filter
When
we left you in our last step, we were ready to select
a Printer Filter in the Red Hat printtool utility.
Click the Select button next the heading Input Filter.
This will open a menu that will list the available
printer filters. If you're not sure what type of printer
yours is, check the make and model and see if it is
in the menu list. If not, select a printer filter
that is similar to your printer, especially if the
make is the same, but the model is not. Once you choose
your filter, don't worry about the other settings
you see on this menu. You can tweak these later when
you know that the printer filter you've chosen works.
Once
you've chosen a printer filter, click OK until you
return to the printtool main menu. Close the printtool
menu and take a look at your /etc/printcap file. You
should see settings that look like this:
##PRINTTOOL3## SMB printerfiltername
lp:
:sd=/var/spool/lpd/lp:
:mx#0:
:sh:
:if=/var/spool/lpd/lp/filter:
:af=/var/spool/lpd/lp/acct:
:lp=/dev/null:
The
printerfiltername will correspond to the one you chose
in the printtool utility. As you can see, without
doing a lot of reading on how to create /etc/printcap
entries manually, you'd find it difficult to get it
right the first time without using printtool.
Step
15: Testing the printer
To
test the shared printer from Linux, try printing any
text file with the lpr command in a terminal window.
Try the command
lpr
/etc/printcap
to
print your printcap file. The file should print, but
if it doesn't, check the following:
Is your Windows machine on, the printer online and
have paper?
Are the Samba server daemons running on your Linux
machine?
Run the Samba utility testprns to make sure all entries
in your /etc/printcap file are correct. Use this especially
if you manually edit the file.
Check your Samba logs for errors.
If printing to the Windows printer does work, you
should be able to print from all of your programs.
Open a browser and try to print a web page for the
final test. If the web page prints, you're ready to
go!
Step
16: What shares are available on your network?
End
users always seem to get left out of the information
loop. If not left out, they're the last to know. If
you know that Samba is configured on a network you
use, there's a simple Linux command that you can use
to determine what shares are available from a Samba
server.
Of
course, Samba has to be installed on your Linux system
too, but you'd have to have it installed to use a
shared Samba network device anyway.
If
you know the name of a Samba server on your network
and want to know what devices it's sharing, run the
smbclient utility. It should be located in either
the /usr/local/samba/bin or /usr/bin directory on
your system. Run this command in a terminal window
to find out what a particular Samba host is sharing
with the network.
smbclient
-L sambahostname
Step
17: Getting help with Samba online
Don't
feel too bad if you don't get your Samba configuration
right the first time. Many experienced Linux users
have trouble, and it's mainly because there are so
many places that you can go wrong. Using the correct
syntax in your configuration files is the usual culprit,
so always double-check your work with the testparm
and testprns utilities.
You
can also find a lot of Samba information online. The
documentation for Samba is thorough, but can be over
the head of beginners at times. Always check your
man pages for Samba as well. you'll find all variables
for your Samba configuration here along with their
definitions.
|