Tux Knows It's Nice to Share, Part 5

Marcel Gagné

Issue #0, linuxjournal.com

Do you wanna dance? Considering what we are going to talk about today, this seems like a good title, but the music in the background isn't exactly dance music (although Gordon Lightfoot does rock, kids). Oops! Sorry, Bruce Cockburn just kicked in. Nevertheless, this kind of rambling at the beginning of a technical column can only mean that you have found the SysAdmin's Corner at Linux Journal's web site with your faithful host, me (Marcel Gagné). Welcome back, everyone. Nice to see your smiling faces here at the corner where we discuss all things (techie && Linux).

So, if you've been following the last four articles in this series, you've now got your NFS running, an NIS server and some clients going, and all those shares are mounting and unmounting automatically because of your new old friend, the Linux automounter. Life couldn't be better. Until . . . that guy in marketing decides he wants you to back up his department's PCs and, since they are all running out of space (those Flash games take up a lot of space), he would like you to set up an NT server on the network to do both of these things. You are at a loss for words, and your blood pressure is on the rise. Install NT? Never!

Luckily, you run Linux and providing file space to Windows clients is nothing a little dance won't fix. No, not on his head. I'm talking a little Samba, the Linux/UNIX file and print services program for that other OS. Heck, why don't you let those marketing types share the printers as well? They won't appreciate it, but you'll get a great deal of satisfaction from it <insert appropriate smiley here>. For those of you who are sitting at home with a Windows 95 workstation or two sitting alongside your Linux server, this is also for you.

Samba was originally developed by Andrew Trigdell in the land down under. Using the SMB (server message block) protocol, Samba makes it possible to share resources between a surprisingly wide variety of operating systems. SMB, like many networking protocols, does continue to evolve as developers do what developers do. Consequently, the current version (or incarnation, if you prefer) of the SMB protocol is actually called CIFS, for common Internet file system. Hey, I don't make this stuff up. In case you are wondering where NetBIOS fits into this picture, that's what SMB evolved from, although NetBIOS isn't a protocol so much as an API (application programming interface) designed to provide the building blocks for creating LAN software. To keep as much brevity as I am capable of, I won't go back any further than that.

Now, despite my jokes about Windows and the marketing guy, Samba can provide file sharing services between Windows 95/98/NT, OS/2, VMS, AIX, HPUX, Linux (of course) and many others. While most people tend to think of Samba as the means by which we replace NT servers with Linux machines, Samba is much more flexible than that. For instance, the lone Windows PC in the office here has the Client for Microsoft Networks loaded so that it can share files in the “Network Neighborhood”. If you remember my example from the last article, I had the PC's C drive not only shared, but automounted. Here's a refresher.

    # Windows PCs
     natika_c           -fstype=smb,username=natika,password=secret         ://speedy/natika_c

I can also mount that drive like this.

     mount -t smbfs -o username=natika,password=secret //speedy/natika_c /mnt/natika

Oh! Susan Aglukark is singing now and that's danceable.

If I had a Samba share defined on my Linux server, I could mount it from another Linux server as though I were mounting a Windows share. I've got a small notebook (called wiltravl) running Linux. On a somewhat larger server (called testsys), I've got Samba running. It has a share defined called winstuff. With NFS, I would specify NFS as the file system type with the -t flag, pass the appropriate options and tell it about the directory we were mounting to.

      # mount -t smbfs -o username=marcel,password=itsasecret //testsys/winstuff /mnt/winstuff

That command, by the way, is all on one line. Now, if I do a df, I will see the file system mounted as one of my local drives.

     [root@wiltravl /root]# df
     Filesystem           1k-blocks      Used Available Use% Mounted on
     /dev/hda1              1517920   1405640     35172  98% /
     /dev/hda5              2514172   1737840    648620  73% /data1
     //testsys/winstuff      6109952   4611072   1498880  75% /mnt/winstuff

Pretty cool stuff. With Samba, I can also make printers available to the Windows machines on the network. Nothing stops me from being able to use Samba exported printers from Linux either. If you wanted to, you could even use Samba as your file sharing system across your network, replacing NFS if the mood takes you (we'll talk about that later). It's a kind of magic (noticing a musical theme in the column yet?).

Anyhow, in order to make this magic happen, we need to get Samba up and running. Just about every Linux distribution CD-ROM comes with a version of Samba which tends to make installation fairly simple by using RPM or dpkg depending on your distribution. You Debian users can of course, use apt-get to pull in the latest distribution from the Debian site. But if you really want the latest and greatest, then you need to get yourself to the Samba web site.

Go to the download section. The latest source is always called samba-latest.tar.gz. If you prefer, you can also find recent binaries for a variety of platforms, but they won't necessarily be as up to date as the source files. To build and install Samba from source, unpack the tarball into a temporary directory and follow these steps.

     tar -xzvf samba-latest.tar.gz

This will create a directory suffixed with the current release number of the Samba source.

     cd samba-2.0.7
     more README
     cd source
     ./configure
     make
     make install

By default, Samba will install in the /usr/local/samba directory. If you would prefer to have it install in another directory structure, then you can use the --prefix=/path/to_dir flag when you do the ./configure step. After the installation has completed (assuming that you accepted the defaults), we need to create a Samba configuration file which will live in /usr/local/samba/lib. The easiest way to do this is to copy the sample file provided along with the source into the appropriate directory.

     cd /tmp_install_dir/samba-2.0.7/examples
     cp smb.conf.default /usr/local/samba/lib/smb.conf

There's a new song starting on the CD I'm listening to. It's Diana Krall...that slow jazzy sound isn't quite a Samba, but it doesn't matter.

Using your favorite editor (yes, mine is vi), open the smb.conf file and change these two parameters : one is called “workgroup = ” and the other is “server string = ”. For the workgroup parameter, I called mine “ROCKGROUP” with a server name of “Marcel's Musical Samba Server”. Now, let's start the Samba dæmons.

     # /usr/local/samba/bin/smbd -D
     # /usr/local/samba/bin/nmbd -D

You'll want to add this to your startup scripts in rc.local. (If you are looking for some details on how to do this, I've covered this in a past article.) Say that your server is called “myserver”. To test Samba and see whether you have done everything right, type the following command.

     /usr/local/samba/bin/smbclient -L myserver

If everything worked smoothly, you should see something like this appear on your screen.

     added interface ip=192.168.1.100 bcast=192.168.1.255 nmask=255.255.255.0
     Password:
     Anonymous login successful
     Domain=[ROCKGROUP] OS=[Unix] Server=[Samba 2.0.7]

             Sharename      Type      Comment
             ---------      ----      -------
             IPC$           IPC       IPC Service (Marcel's Musical Samba Server)
             lp             Printer
             hp710c         Printer
             colour         Printer
             win            Printer

             Server               Comment
             ---------            -------

             Workgroup            Master
             ---------            -------

I always wanted my own rock group. Speaking of magic, did you notice? Without doing anything other than starting Samba with a valid configuration file, my printers are available as resources on the network. It is not necessary to define each printer individually, Samba takes for granted they are shared resources (you are running a server after all).

And so, once again, I must wrap it up for another week. This is another one of those BIG topics and I sure won't be able to cover it all in one column. Before I go...I don't do this every week, I realize, but I want to thank everyone who writes me, comments and otherwise contributes suggestions or ideas to this series. You know who you are and I appreciate your input. And now, your humble geek and narrator must sign off (to the sound of the Barenaked Ladies). Until next we meet on this, the <exaggeration>sunniest corner in the whole of the world wide web</exaggeration>, remember what your Momma said, “It's nice to share”.

Looking for past articles to this series? Click here for a list.