The magazine of the Melbourne PC User Group
Build a Samba File Server
Rob Reilly |
|
|
In this article, Rob Reilly takes you on a step by step walk through
setting up a Samba file server on a Linux machine — it creates a network
server for your Microsoft Windows machines. |
Why A Samba File Server?
Samba is an Open Source program running on a Linux server and it's designed to
replace Microsoft file shares. Microsoft Windows clients can transparently store
and access files without ever knowing that they are not connected to an NT or
other Windows server machine. Samba on Linux is reliable, fast, low cost and
doesn't have any licensing issues.
You'll need a current version of Linux, such as SuSE Linux 8.2 Professional. Any
Intel based machine can do duty as the server. For users just getting started an
older 200 MHz. Pentium PC with 64 MB RAM and a 3 GB disk would work just fine.
The server should be connected to your local area network (LAN), along with your
Microsoft Windows PCs.
This article will get you started with a basic Samba configuration on a test or
home network. Security will be minimal and my example will demonstrate the
operation of a single Linux/Samba server and a single Microsoft Windows client
machine.
Be aware, too, that the example will use the TCP/IP network protocol for
communication, not the proprietary NetBEUI protocol common on many Windows only
networks. You may have to reconfigure or add the TCP/IP protocol, under Windows
Networking, for your Windows machine. Refer to the reference list for books and
links to help with these tasks.
Set Up Samba On Your Linux Server
Most Linux distributions (otherwise known as a CD set) have a version of Samba
bundled in. Under SuSE Linux 8.2, which is my favourite, you can use the YAST
installation program and search on "Samba" (See Figure 1). You'll find "Samba
server" and "Samba client utilities". As you proceed, make sure there is an "i"
in both left hand columns. If they're blank press the space bar until an "i"
appears. Then type "Enter" and feed the correct CD into the CD drive. YAST will
go through its motions and you'll end up with the Samba packages installed and
ready to configure.
|

Figure 1. The YAST installation program search for "Samba". |
Red Hat, Mandrake and other Linux packages have their own installation
techniques.
Configuring Samba on a Linux machine requires a few steps but it's quite
straightforward. See Figure 2 for a diagram of the steps.
We Need A New User
The first thing you'll need to do is set up a new Linux user. The basic
security mechanism on Linux is the user name and password. These are kept
in encrypted files with access provided only to the "root" user. Root
creates the user name, the new user's home directory and sets the new
user's file permissions. The user can then choose his/her own password.
Samba, also uses a separate user name and password list for remote Windows
user access. The newly created Windows user needs to appear in both the
Linux and Samba user lists, and must have an account on the Windows
machine to gain access to Samba network shares (directories).
We'll use "test5" for the example user, but you use any name you choose.
Just replace "test5" with your chosen user name.
On the Samba server log in as "root". On the KDE desktop this is
accomplished by clicking on the little computer screen icon on the task
bar, at the bottom. An X-terminal will pop up with a command prompt.
The command prompt on my Samba machine (for a normal user) is "rreilly@moe:~>".
Yours will be different. You'll have to "switch user" to root to
do the Samba configuration.
Type:
rreilly@moe:~> su root
|

Figure 2. Diagram of the Samba server setup steps. |
And then enter the "root" password.
You'll notice that the command prompt has changed to [something#]. The # means
that you are the "root" user. Be very careful when you are logged in as "root"
because you can cause a lot of damage to your system if you're not careful. Make
sure you log out of "root" as soon as you've finished. I'll repeat that because
it's critical; Make sure you log out of "root" as soon as you've finished.
Once at the command line you can enter the following commands to configure
Samba.
(remember moe# is the prompt on my system - your prompt will be different - and
to assist, the actual command is in italics):
moe# cd /home
... changes directory (cd) to home on the Linux system.
moe# mkdir test5
... adds a new home directory for the "test5" user.
moe# useradd -d /home/test5 -s /bin/false -r test5
... adds a new user to the Linux user name file.
moe# passwd test5
... sets the new user password under Linux. You'll always have to type the
passwords twice, for verification.
moe# smbpasswd -a test5
... creates the new "test5" user under Samba and enables setting of a password.
You'll always have to type the passwords twice, for verification.
moe# chown test5 test5
... changes the file user ownership from "root" to "test5". Note: you're still
the root user at this point.
moe# chgrp users test5
... changes the file group ownership from "root" to "users". The "users" group
is generally the default group for normal users on a Linux machine.
moe# ls -l
... verifies that the owner and group for the user "test5" are correct.
If all went well, the "test5" user has been created on the Samba server. Don't
exit the root user yet because we are not finished - we need to do some other
"root" tasks.
Editing the Configuration File
To set up the Samba server on our Linux machine we'll need to edit the
/etc/samba/smb.conf
configuration file. This file contains Samba configuration information such as
workgroup name, file security options and file share names. The file can be
edited with any normal Linux text editor, such as VI. Figure 3 shows a basic
/etc/samba/smb.conf
file. Your default
smb.conf file will contain many more
options. Make a backup copy before you start slicing and dicing.
|

Figure 3. The basic /etc/samba/smb.conf file. |
Let's step through the important sections in the
smb.conf
file and edit as we go.
In the [global] section:
Windows/Samba networks need to have a workgroup. Just fill in a name for your
network. Samba doesn't like spaces in the workgroup name.
- Set the OS level to "65". This ensures that the Samba server browse list
overrules all other browse lists on the network.
- Set local master to "yes".
- Set preferred master to "yes". This option will initiate a server browser
election on restart. When you use Network Neighbourhood on your Windows machine
it will then correctly show the network shares (directories).
- Set wins support to "yes". This keeps error messages in the /var/log/samba/log.nmbd
file to a minimum.
- Set security to "user". This provides user level authentication.
- Set encrypt passwords to "yes". We definitely want encrypted passwords
moving between our Windows desktops and the Samba server.
The [test5] section:
This section represents the directory where you would store your Windows files.
- The comment line simply gives a description of this section.
- Set the path to "/home/test5". You'll replace "test5" with another user name
as you add people to your server.
- Set read only to "no". If you want to prevent yourself (or anyone else) from
writing to your home directory, while on a Windows desktop, set this to "yes".
You can always log into the Linux machine directly and get to your files.
You should choose a reasonable name for the aforementioned section, since this
will be the name that shows up in the Network Neighbourhood or file share
listings on the Windows desktop machines. The "global" name, of course, doesn't
show up as a directory. In our example, when using Network Neighbourhood on a
Windows machine, we would see the "test5" directory under the "moe" server name.
Moe is the network name of my example Samba server. Remember the "moe#" prompt
on the command line?
In order for the edits in
/etc/samba/smb.conf file to take effect,
we'll need to restart the Samba server. This command should be issued whenever
you make a change to the
/etc/samba/smb.conf file. Hopefully, at
this stage you are still logged in as "root". Restart the Samba server with:
moe# rcsmb restart
It's possible to test the Samba server before we tackle the Windows desktop
setup. Here are another couple of command lines and descriptions of what they
do.
moe# testparm
This command will check the
/etc/samba/smb.conf file for validity and
then give a listing of all of the configuration values (both the defaults and
those we set) for the Samba server. You would actually execute testparm before
the rcsmb command, but I wanted to group the testing steps together. You should
see a line in the output to the screen that says "Loaded services file OK".
Refer to Figure 4 for sample output.
|

Figure 4. Output of the "testparm"
command. |
We can also test that the server is making
network shares available to your network. On the command line type:
moe# smbclient -NL moe
Take a look at the output under the heading of share name. You should see the
"test5" share. Refer to Figure 5 for sample output.
|

Figure 5. Output of the "smbclient" command. |
Remember "moe" is my Samba server hostname. My Samba server is also known on my
network as 192.168.2.12, which is its IP address. Be sure to use the server
hostname or IP address assigned to your Samba server. The hostname usually
appears as part of the command line prompt like "moe#". If it doesn't show up
there, use the following command (# being the prompt for root):
# echo $HOST
Samba works very well behind firewalls on local area networks. A typical small
business setup would be a Samba file server with one or more Windows client
desktop machines. It's possible to use Samba across subnets or even over a
public network (like the Internet), but there is considerably more tweaking and
configuration that needs to be done to make it secure. Security with Samba over
WANs (wide area networks) is a complicated subject and beyond the scope of this
article. Take a look in the reference list for some books and Web sites on the
subject.
Configure Your Windows Machine
The last part of setting up the passwords and such, needs to be done on your
Windows machine. I converted almost totally over to Linux several years ago and
as a consequence have one lone Windows 98 machine on my network, for the kids
and their games. Adding users to your Windows 2000 and later computers should be
pretty similar.
On your Windows machine do the following to set up the "test5" user.
- Click on the "Start" button.
- Click on the "Log Off ...." menu selection.
- Log off Windows - click "yes"
Then in the "Enter Network Password" box, type in your new user name and
password. In our example, it would be:
User name:
test5
Password: 5testing
This is the password I chose, when I set up the test user on the Samba server.
In addition to typing your new user name and password (for network access), you
may be asked to enter your password, a second time, for "Windows" access.
There are several ways to access your newly created Samba server and its files.
Since I'm using Windows 98 the example will use the tools and techniques bundled
into that version. Later versions of Windows will use similar tools.
The first method of connecting to the Samba server is through Windows Explorer.
Start up Windows Explorer and follow these steps:
- Click on "Tools".
- Select a drive letter to use. In my example it was "E:".
- Click "Map Network Drive".
In the Path box enter "\\MOE\test5".
Of course, you would enter whatever directory name you set up when you edited
the /etc/samba/smb.conf file. The path name maps to file in the /home directory
on the MOE Samba server. It's not necessary to put in the
/home part in the
Windows network path.
- Click "OK" to complete the job. You can also put a check mark in the reconnect
box if you want to be connected to the network share when you log back in next
time.
An alternative route to your network share is through the Windows Network
Neighbourhood. The steps are pretty simple:
- Double click on the Network Neighbourhood icon.
- Double click on "Moe".
- Double click on "test5" and there are your files.
Now think of your new "test5" directory on the Samba server as just another
drive. In my example that would be drive "E:" on the Windows machine.
You can drag files into your new "E:" drive, execute programs that you store
there and generally do anything you would do with a normal local disk drive. The
only real difference is, that network share is on a Samba machine.
The Samba combination is super reliable. Unless you have a power or hardware
failure, your network drive will always be there ready for use.
Troubleshooting Your Samba Server
Suppose your Samba file server doesn't seem to serve files? Areas that you would
look at include the following.
Check to make sure that 3rd party firewall software isn't "protecting" your
Windows machine. I've chased my tail several times when a firewall program has
blocked connections to new servers. ZoneAlarm is my favourite on the old Windows
98 machine. It has a menu where MOE (otherwise known as 192.168.2.12) can be set
up as a trusted host machine.
Another problem might be that you messed up the smbpasswd command. Try getting
rid of the user, in our example "test5" with the following command:
moe# smbpasswd -x test5
Then add the user again with:
moe# smbpasswd -a test5
You should then very carefully add the password.
You might also try logging off of the Windows machine and then back in again as
"test5".
These things should clear up just about any problem you have. If you continue to
have problems, you could also seek assistance from your friendly local Linux
User Group, otherwise known as a LUG. They are located all over the world and
can be found on Google. The people in the LUGs are experts with Linux and can
usually help you diagnose and solve just about any Linux (and usually Windows)
problem. Be forewarned, most LUG members are not very fond of Windows, but since
you're making an effort to convert with Samba, you'll be OK.
You may be so impressed with LUG people, though, that you'll join their group on
the spot.
Wrap Up
That wraps up our adventure through the setup of a Samba file server. There are
hundreds of other options available to enhance the functionality. We've covered
the basics and I encourage you to give it a good try. A Samba server is a very
reliable, stable platform. Once you have your system running, I think you will
be very happy. And, you don't have to worry about licensing hassles, either.
References
http://www.samba.org
The Samba Home Page
http://lugww.counter.li.org/
The Linux User Group Worldwide Home Page
http://www.wown.com/
The WindowsNetworking.com Web site
“Samba Unleashed”
By: Steve Litt.
April 2000
ISBN: 0-672-31862-8
“Using Samba”
By: Robert Eckstein, David Collier-Brown, Peter Kelly
November 1999
ISBN: 1-56592-449-5
“Windows 98 Secrets”
By: Brian Livingston & Davis Straub
1998
ISBN: 0-7645-3186-7 |
About the Author
Rob Reilly, (aka: "Dr. Torque")
robreilly@earthlink.net, is a writer, speaker
and consultant involved in high technology, portable computing and seminars. He
is a strong advocate of recycling and hot-rodding obsolete PC hardware using
Linux. Visit his Web site at
http://home.earthlink.net/~robreilly/.
Reprinted from the March 2004 issue of PC Update, the magazine of Melbourne PC User Group, Australia
|