In-class lab: installation and configuration of Samba

Samba is a software package that comes with most Linux systems. Samba enables you to share file systems and printers on a network with computers that use the Server Message Block (SMB) or Common Internet File System (CIFS) protocols. SMB is the Microsoft protocol that is delivered with Windows operating systems for sharing files and printers. CIFS is an open, cross-platform protocol that is based on SMB. Samba contains implementations of both.

Installation

First, check if samba is not yet installed on your machine by running

# yum list | grep samba
if you see the line that looks like: samba-3.0.82 fedora it means that this package is part of the Fedora but not yet installed. In this case, install the last approved version of samba by running yum install samba

Now, please go to the /etc/init.d directory and make sure that the startup script for samba (smb) is there. Check the current status of the samba service by running service smb status. If the service is not running, start it by means of service smb start. If you do not want to manually start the service every time you reboot your system, configure it to run automatically. This can be done by using the chkconfig command:

# chkconfig --add smb
Now, the smb service is running but we still cannot access it from outside because the ports for samba server are not open in firewall. Please run System/Administrations/Firewall
and make sure you open the ports used by samba service.

Simple configuration

There are three ways of configuring samba server:

Manual configuration

Samba configuration file is called smb.conf and located in the /etc/samba directory. This is a pure text file with a lot of comments that explain pretty much any detail of the file instruction. In order to practice with the file a little bit, let's create a directory that can be shared by some users.

  1. create a directory which you will share in the future (let's say /var/smbshare)
  2. go to the /etc/samba directory and make a backup copy of smb.conf
  3. open the smb.conf file and scroll down to the very end of the file. You should find yourself in the Share definitions section
  4. append the following lines to the file
    [smbshare]
    	comment = Public share
    	path = /var/smbshare
    ;	writeable = yes
    ;	browseable = yes
    	valid users = mary
     
    What we just entered means: we create a new smb share named smbshare (see square brackets), path to which is defined as /var/smbshare, the only user who can access it is mary. Please note the semicolon at the beginning of the writeable=no line. Semicolon means the same as the pound sign (£) – comments.
  5. we are almost ready to check how it works except one thing – user authentication. According to the default settings, samba authentication uses individual user's authentication and their encrypted passwords. In order to add another samba user, we need to use smbpasswd command. Thus, to create samba user mary run:
    # smbpasswd -a mary
    and type a password for this user.
  6. Do not forget to restart the samba service in order for new setting to take an effect:
    # service smb restart
  7. One last touch is to let the Linux security program SELinux access information in the shared directories. Please start Applications/System Tools/SELinux Management and check the samba settings as shown in the Figure below.
    You can achieve the same result by running the following commands from the shell:
     # setsebool -P samba_export_all_ro=1
     # setsebool -P samba_export_all_rw=1
     # setsebool -P samba_enable_home_dirs=1
     
We are done with the manual configuration. Now, let's see if this sharing actually works. Please do the following:

Using samba configuration program

A special program provides a nice window interface to samba configuration. In fact, this program does nothing but writing special instructions into the smb.conf file but it does it without typos :). To run the program, go to System/Administration and look for Samba tools. If it's not present, install it by

# yum install system-config-samba
Once it's installed, run it and enter the root password at the prompt. You'll see a window like the one below
but with the smbshare already listed. Play with the program to add another user bobby and let this user access the smbshare share.

Configuring with SWAT

Samba Web Administration Tool (SWAT) is a samba configuration tool that can be accessed through any web browser. To install it, run yum install samba-swat. Once installed, we need to turn the swat service on by running chkconfig swat on and actually starting it. The difference between the swat service and other services we have looked at is that the swat service is executed through the xinetd service. Thus, in order to start it, we have to restart the xinetd. This can be done by service xinetd reload. If the swat service successfully started, we can now access it through a web browser.

To configure samba server through the web interface, start a web browser from your Linux machine and go to the http://localhost:901

At the authentication prompt enter the super user's credentials. Using this tool create another share and make sure it works just as well as GUI configuration.

Additional practice

Using SMB protocol to access Windows shares from Linux machines

In order to access Windows share from your Linux machine, you need to use the mount command with appropriate file system specified and the full address of the network share. Let's test this by doing the following:

Additional reading