Got Windows? Get Samba. Be Happy.

It's happened. My significant other has finally moved her laptop into my home. She's running Windows 95, however, and wants to connect to my Linux machine to make use of our printer and the larger hard disks. I have both the Applix and StarOffice suites installed, so I can import and export Word and other Microsoft files, which she can use in Windows. Her office PC is able to share disks and printers and files on the company's network, but can we do the same thing on my home network?

It’s happened. My significant other has finally moved her laptop into my home. She’s running Windows 95, however, and wants to connect to my Linux machine to make use of our printer and the larger hard disks. I have both the Applix and StarOffice suites installed, so I can import and export Word and other Microsoft files, which she can use in Windows. Her office PC is able to share disks and printers and files on the company’s network, but can we do the same thing on my home network?

Open source software to the rescue! All we need to do is install and configure Samba, a file- and print-sharing system available for Linux.

Samba Overview

Samba is a very comprehensive suite of programs that allow a variety of operating systems to communicate with one another. You need to have computers networked together to use it. If you don’t have a network, then you won’t be able to do much with Samba.

Administrators of large-scale networks use Samba to connect hundreds of Unix systems with hundreds of Windows and other types of workstations. A number of excellent books are dedicated to the intricacies of Samba, but we can cover the basics here — enough to get you started by connecting a Linux system, a Windows system, and a shared printer into your own home-based mini-network.

Samba uses Microsoft’s Server Message Block, or SMB protocol. SMB originated in the 1980s and was later adopted and extended by Microsoft. SMB runs on top of another protocol — NetBIOS — which, in turn, runs on top of other transport-layer protocols such as IPX and TCP/IP. Fortunately, you don’t need to know or understand any of that. All you need to know is that Microsoft uses SMB to let you share files over a network.

Microsoft never published the details of the SMB protocol, which made it difficult for programmers to develop systems that use it. A group of very clever people led by Andrew Tridgell, however, reverse-engineered the protocol and used this information to create the early versions of Samba. Being open source, Samba is now maintained and extended by a large group of volunteers from around the world.

What Samba Does

Newbies WinShare 1
Figure One: Mapping a network drive.

If you’ve ever used a Windows PC on a network, then you know that you can “map” or “share” network drives. You do this through Windows Explorer (the Windows file manager), selecting “Tools->Map Network Drive…” (see Figure One). Assuming that your network is properly set up to allow it, you should be able to use this tool to make a disk on another system appear as if it were part of your local machine’s filesystem. In other words, you could make another machine’s D: drive appear to be the G: drive on your system.

Samba can do much the same thing, allowing directories on your Linux system to be shared with a Windows PC. Samba also lets you share other resources, such as printers.

In Figure One you’ll see that it’s possible to share drives from a system named Shibuya with a Windows PC. Shibuya is actually a Linux system running Samba.

Samba is included with most popular Linux distributions. If Samba hasn’t already been installed on your system, the easiest way to install it is to download the binary (precompiled) packages. Naturally, the place to start would be the official Samba Web site at http://www.samba.org.

Samba Configuration

After installing Samba, you configure it to “advertise” certain directories and resources that other systems can access. The details about which resources to advertise are contained in the Samba configuration file, /etc/smb. conf. This configuration file can get pretty complicated when you’re setting up a large network, but for a small home network, you should only have to add a few lines to the file for each directory or resource you want to share.

You can configure Samba by editing the smb.conf file manually (with a text editor), but the easiest way is to use the SWAT Web-based interface.

smb.conf: The smb.conf man page is more than 75 pages long. Pretty intimidating. Luckily, you can set up Samba between two or three machines without digesting the full 75 pages of man documentation. In fact, you can get away with knowing only a few basics, which we’ll discuss here.

It’s important, however, that you understand that there are some serious security concerns involved with Samba. In “advertising” a directory as accessible, that directory can be directly accessed from the other systems on your network. If you have a large network, or if your network is accessible from the Internet, your directory might end up being advertised to more machines than you think.

If you are concerned about your system security, I recommend that you read one of the Samba books. The examples I provide here are very simple and provide minimal security. This should be okay for a small home network that is usually not accessible from the Internet.

The smb.conf File: When you install Samba, it includes a copy of the /etc/ smb.conf file. You should configure Samba by modifying this file, rather than by trying to create your own smb. conf file from scratch. The default file contains fairly extensive documentation that will guide you through the process of enabling, disabling, or changing the various options. In the file, the documentation appears in lines preceded by a ; or a #, which tells Samba to ignore those lines when reading the configuration.

The smb.conf file is divided into sections, each of which begins with a bracketed keyword. To set up your small home system, you will need to edit the [global] section and add a brief entry for each directory or resource you wish to advertise.

smb.conf: [global] Section: A set of general Samba parameters are defined in the [global] section of the smb.conf file. This is where you specify the name of the Windows workgroup and the IP addresses of the machines allowed to access the Samba-shared resources.

In my configuration file, I have the following in the [global] section:

workgroup = my_workgroup_name
hosts allow = 172.16.127.
security = user

The workgroup line is where I specify the name of my Windows workgroup, and hosts allow is where I specify that the machines on my home network (which all have IP addresses beginning with 172.16.127) are allowed to access the directories being advertised by this computer. The security line is where the basic security level is specified. Again, if your machine is part of a larger network or is on the Internet, be careful. And make sure you read the Samba security documentation thoroughly.

Shared Directories: The [global] section affects all directories exported by your Linux system, but user settings are specific to each shared, or exported, directory.

The following is from my smb.conf file:

comment = “Hal’s
home directory”
path = /home/hal
browseable = yes
writable = yes
available = yes
public = yes
only user = no
create mode = 0750

The section name ([hal]) will be reported to the Windows client, and the comment provides more description if the client requires it. The path is the directory to be exported. The remaining lines specify that the client can browse and write to the directory, the various permissions for that directory, and the permissions that will be assigned to the files that are created within that directory. These are only a few of the possible parameters that can be assigned, and more details can be found in the man page. You will need to create a [user] section for each directory that you wish to export.

Printers: You can make the printer attached to your Linux system available to Samba clients. The following [printers] section is taken from my smb.conf file.

comment = “Laserjet”
path = /var/spool/lpd/lp
printer = lp
public = yes
printable = yes
print command = lpr -r -h
-P %p %s

It may be necessary to make the print spool directory (/var/spool/lpd/ lp) accessible by all users with the command chmod a+rwx /var/ spool/lpd/lp. Try adding this command if you have problems configuring the print sharing.

Newbies SmbTest 2
Figure Two: testparm output.

Testing smb.conf: Once you have finished editing your smb.conf file, you can verify it using the testparm command. This reads the smb.conf file and displays any errors that it finds. When the errors have been displayed, press “Enter” to display all of the parameters that have been set. Figure Two shows the testparm output from my system (the [global] section has been truncated due to length).

Starting Samba Daemons

Samba’s client communication is handled in the background by a number of daemon programs that can be configured to start automatically when your Linux system boots. Daemon is the name given to any type of program that runs constantly in the background. If your Samba daemons are not automatically started, you can specify them to do so using a utility such as linuxconf. You can also start the daemons manually with the following commands. (Note that you must be logged in as root to use these.)

# /usr/sbin/smbd -D
# /usr/sbin/nmbd -D

When the daemons are started, they read your smb.conf file and advertise the directories and services that are configured within that file. By default, the daemons recheck the smb.conf file every 60 seconds. Changes made to the file will automatically take effect the next time the daemons check the file.

Making it Work: Configuring Samba with SWAT

The Samba Web Administration Tool (SWAT) lets you to manage Samba with your browser.


SWAT is an easy way to edit the Samba configuration file (smb.conf), but to make SWAT work, you have to get in there and first edit both the /etc/services and /etc/inetd.conf files. Add the following line to your /etc/services file:

swat 901/tcp

And the following line to your /etc/inetd.conf file:

swat stream tcp nowait,400 root /usr/sbin/swat swat

This assumes that SWAT is installed in the /usr/sbin directory. If SWAT is in a different directory, change that part of the line to reflect its actual location.

Newbies Swat Intro 4


Once these files are properly configured, launch your Web browser and type the following in your browser’s “Location” field (this is the place where you usually type URLs):

When prompted, enter the username and password for the root

user on your system. The main SWAT menu allows you to access all of the online Samba documents.

Newbies Swat Globals 5


If you press the “Globals” button, you will have access to all of the global variables in the smb.conf file, so you can set up the Windows workgroup names and IP addresses of machines on your network.

Newbies Swat Create 6


To create a shared directory using SWAT, click the “Shares” button. Enter a name for the share in the text field to the right of the “Create Share” button, then click the button. You will then be able to specify the rest of the parameters required to create that shared directory.

Configuring Windows

I’m using Windows NT to access the shared drives on my Linux server. Once I finished configuring and testing Samba on my Linux machine, I restarted my NT computer; the shared drives were automatically accessible.

If you’re using Windows 95 or 98, you may want to set user passwords. To do this, select the “Passwords” icon from the Control Panel. Enable the “Users can customize their preferences…” option under the “User Profiles” tab. Under “Change Passwords,” simply follow the instructions to assign yourself a username and password. Make sure these are the same as the ones you have on the Linux system you wish to access. When you select the “Network Neighborhood” icon on the Windows desktop, you should be able to access the shared drives.

If you encounter any problems with Samba, these are likely to be related to security settings and passwords, and you should read the Samba documentation and other texts mentioned in the More Reading sidebar. You should also check the Samba HOWTOs and FAQs.

One final note: February’s Newbies column had an error in it. Because of an editing error, we incorrectly described Linux’s pwd command, which prints the name of the directory you’re working in. To print the files in your directory, use the ls command.

Printing to a Linux Printer from a Windows PC

Newbies Add Printer 7

If you have specified the printer on your Linux machine as a shared resource in Samba, you will be able to access that printer from your Windows box. To use the printer, however, you will first have to add that printer to the list available on the Windows system. This is a pretty easy thing to do.

First, select “Printers” from the Windows Control Panel, then select “Add Printer.” Select “Network Printer” and click “Next.” In the window that pops up, navigate through the network display to locate the printer on your Samba server. Double-click the printer’s icon and follow the remaining instructions.

When you’re finished, the Linux printer will be added to the list of printers available to your Windows machine.

More Reading

For Bookworms

Blair, John D. (1998), Samba: Integrating Unix and Windows, Specialized System Consultants, Seattle, WA.

Eckstein, R., Collier-Brown, D., Kelly, Peter (1999), Using Samba, O’Reilly & Associates, Sebastopol, CA.

For Web Crawlers

Samba’s Web Site: http://www.samba.org

“The Story of Samba,” From Linux Magazine’s archives: http://www.linux-mag.com/1999-09/samba_01.html

Hal Moroff has been developing Unix systems and applications for 20+ years. He’s new enough to Linux that he’s finding new things every day. He can be reached at halm@ieee.org.

Comments are closed.