Originally Published: Thursday, 14 June 2001 Author: Josh Boudreau
Published to: learn_articles_firststep/General Page: 2/2 - [Printable]

Getting Started With Networking for Linux Part 3; Sharing File Systems

Josh Boudreau returns to Linux.com Learn with the third part of his popular introduction to networking series. In part three of Getting Started with Networking for Linux Josh takes a look at sharing file systems between Windows and Linux boxen on the same network, using technologies like Samba and smbmount.

Installing Samba  << Page 2 of 2  

Installing Samba

If you have both Linux and Microsoft Windows computers on the same network and you want to share files between them, you will need to install the Samba software package. Most Linux distributions ship with a pre-compiled version of Samba but if yours does not the source code for Samba can be downloaded from www.samba.com. Samba can be compiled and installed with the following commands once you have downloaded the source code.

tar zxvf samba-latest.tar.gz (extract source code)
cd samba-latest/source (change to the samba source directory)
./configure --with-smbmount (configure build environment)
make (build Samba package)
su (change to super-user)
make install (install files)
exit (exit super-user shell)

By default this will install the Samba files in /usr/local/samba. If you want to install it in a different directory add --prefix=/samba/install/dir to the ./configure command.

Samba comes with a Web Configuration utility called swat and if you want to use it you will need to add a few lines to /etc/services and /etc/inetd.conf. In /etc/services add the following line if it does not already exist:

swat 901/tcp # Swat, Samba Configuration Utility

You also have to add a line to /etc/inetd.conf to start the service if it's requested so add the following if it does not already exist.

swat stream tcp nowait.400 root /usr/local/samba/bin/swat swat

Please note that the path on that line might be different than the one on your system (especially if you didn't install Samba in the default directory) so change it according to your system. Once both these files are changed inetd must be re-started: you can do this by typing killall -HUP inetd at your shell prompt.

If you're having difficulties installing Samba, the good folks at O'reilly provide a free version of the book Using Samba which is distributed with the Samba source code and is found in samba/docs/htmldocs/using_samba.

Samba Configuration

Before starting up the Samba daemons we still need to build our configuration file for Samba. If you set up swat like I explained in the previous section you can connect to the swat configuration utility with your web browser by entering http://hostname:901 as the URL. This program will give you options for building the Samba configuration file. Since we're not using all of Samba's features I will list a simple configuration file that can get you started. By default this file goes in /usr/local/samba/lib/smb.conf but if your Linux distribution came with a pre-compiled version it's also common to find it in /etc/smb.conf.

[global]
netbios name = MyMachine
workgroup = Workgroup
server string = My Samba Server
security = SHARE
encrypt passwords = Yes

[incoming]
comment = ftp directory
path = /home/ftp/incoming
read only = No
guest ok = Yes
hide dot files = No

[homes]
read only = No

This simple configuration file configures the netbios name of our machine and tells Samba which Microsoft Workgroup our computer is a part of. Both the [incoming] and [homes] sections are exported directories that other computers will have access to. The [homes] share is a special one that lists only the home directory of the user connecting to our Samba server. When a Microsoft Windows user browses your network with the Network Neighborhood utility, he or she will see incoming and their home directory(if he or she has one) as shared file systems.

To add more shared directories to your Samba server simply copy the [incoming] example, rename it and change its path value. Various permission settings such as read and write access must also be specified like we did before. For a full list of options you can specify in your smb.conf file, type man smb.conf at you shell prompt.

Starting Samba and Adding Users

Once you have the configuration done you can start Samba by typing the following at your shell prompt:

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

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

If your configuration file is valid these two daemons should sit in the background and listen to network requests made of your Samba server. To let users have access to your server they must be present in the smbpasswd file. The Samba user authentication is completely separate from your Unix /etc/passwd file.

Adding users to Samba can be done with the smbpasswd utility. To add a new user, type the following command at your shell prompt:

/usr/local/samba/bin/smbpasswd -a username

After typing this command you should be prompted to provide a password for the new user. Remember that this username and password is not the same as the one used to log on your system. The username should be the one the user uses on his Microsoft Windows computer.

Mounting Microsoft Windows Shares

The only thing left to see is how to mount Microsoft Windows shares on your Linux computer. During the installation process we passed --with-smbmount as an argument to ./configure. This argument built the smbmount utility which is used to mount file systems shared on a Windows computer. You can mount Windows shares on your Linux machine by typing the following command at your shell prompt:

smbmount //remotemachine/service /mnt/point -o username=user,password=pass

This command would mount the directory at //remotemachine/server at /mnt/point on your Linux machine. You can pass some command arguments to smbmount to specify which username and password to use (like we did above). Other useful arguments that can be passed to smbmount are ip=ipaddress and workgroup=workgroup which tells smbmount at which IP address the machine is located and which workgroup the machine is a part of, in case the smbmount command fails to find the machine.

For those of you using X11, there's a graphical front-end to smbmount called LinNeighborhood that looks similar to Network Neighborhood under Microsoft Windows. It lets you browse Microsoft networks and mount file systems. LinNeighborhood can be downloaded at www.bnro.de/~schmidjo/ and is definitely worth checking out.

Additional Resources

For additional information visit the Samba Web Site and be sure to take advantage of the great book called Using Samba that O'reilly has made available for free.

You might also wish to read the previous articles from this series which are Getting Started With Networking for Linux and Getting Started With Networking for Linux; Configuring DNS for your network with BIND.





Installing Samba  << Page 2 of 2