Samba and Samba Client

Samba allows both CentOS resources to be shared with Windows systems and Windows resources to be shared with CentOS systems. CentOS accesses Windows resources using a package named samba-client.

CentOS resources, on the other hand, are shared with Windows systems using a package named samba. Typically, the samba-client is installed and configured by default allowing the user to browse available Windows resources without any additional work (this is covered later in the chapter). In order to allow a CentOS 6 system to share resources with Windows systems, however, some more work is required.

Installing Samba on a CentOS 6 System

The default settings used during the CentOS 6 installation process do not install the samba package. Unless you specifically requested that Samba be installed it is unlikely that you have Samba installed on your system. To check whether Samba is installed, open a terminal window (Applications -> System Tools -> Terminal) and run the following rpm command:

 

# rpm -q samba

 

If Samba is installed, the rpm command will generate output similar to the following:

samba-3.5.4-68.el6_0.1.x86_64

 

If Samba is not installed, rpm will return with “package samba is not installed”. That being the case, it can be installed using the yum command-line tool:

su –

yum install samba

 

The above command will install both the samba package and the samba-common dependency package.

If you prefer to use the graphical tool to perform the Samba installation, select Applications -> Add/Remove Software, enter the root password if prompted to do so and then perform a search for Samba. When the list of matching packages appears, set the checkbox next to the samba and samba-common packages and click on Apply to initiate the installation.

 

Configuring the CentOS 6 Firewall to Enable Samba

 Next, the firewall currently protecting the CentOS 6 system needs to be configured to allow Samba traffic. To achieve this, run the Firewall Configuration tool by selecting the System -> Administration -> Firewall menu option and select the check box next to Samba in the Trusted Services section of the tool. Click Apply and OK to commit the change.

Before any resources on the CentOS system can be accessed from the Windows systems, however, some additional configuration steps are necessary.

 

Configuring the smb.conf File

In releases of CentOS prior to version 6, a user friendly graphical tool named system-config-samba was provided to assist in the configuration of Samba. In CentOS 6, however, this tool has been removed. This means that the Samba environment must be configured manually within the /etc/samba/smb.conf file and using the smbpasswd command line tool. Whilst the loss of system-config-samba may be mourned by those who relied on it, the tool’s simplicity actually masked many of the more advanced features of Samba. In practice, much more can be achieved by taking the time to understand the intricacies of the smb.conf file.

 

Samba is a highly flexible and configurable system that provides many different options for controlling how resources are shared on Windows networks. This flexibility can lead to the sense that Samba is overly complex to work with. In reality, however, many of the configuration options are not needed by the typical installation, and the learning curve to set up a basic configuration is actually quite short.

 

For the purposes of this chapter we will look at joining a CentOS 6 system to a Windows workgroup and setting up a directory as a shared resource that can be accessed by a specific user.

 

The first step, therefore, is to gain root privileges and to load the /etc/samba/smb.conf file into a suitable editor, for example:

su –

gedit /etc/samba/smb.conf

 

Configuring the [global] Section

The smb.conf file is divided into sections. The first section is the [global] section where settings can be specified that apply to the entire Samba configuration. Whilst these settings are global, each option may be overridden within other sections of the configuration file.

The first task is to define the name of the Windows workgroup on which the CentOS 6 resources are to be shared. This is controlled via the workgroup = directive of the [global] section which by default is configured as follows:

workgroup = MYGROUP

 

Begin by changing this to the actual name of the workgroup. For example, if the workgroup is named WORKGROUP (the default for most Windows networks):

workgroup = workgroup

Configuring a Shared Resource

The next step is to configure a shared resource (in other words a resource that will be accessible from other systems on the Windows network). In order to achieve this, the section is given a name by which it will be referred to when shared. For example, if we plan to share the /tmp directory of our CentOS 6 system, we might entitle the section [tmp]. In this section a variety of configuration options are possible. For the purposes of this example, however, we will simply define the directory that is to be shared, indicate that the directory is browsable and writable and declare the users that are allowed to access the shared resource (in this case a user named demo):

[tmp]

path = /tmp

writeable = yes

browseable = yes

valid users = demo

 

Creating a Samba User

Any user that requires access to a Samba shared resource must be configured as a Samba User and assigned a password. This task is achieved using the smbpasswd command line tool. In our example smb.conf file we stated the user demo is entitled to access the /tmp directory of our CentOS 6 system. In order to fulfill this requirement, therefore, we must add demo as a samba user as follows:

# su –

# smbpasswd -a demo

New SMB password:

Retype new SMB password:

Added user demo.

 

Now that we have completed the configuration of a very basic Samba server, it is time to test our configuration file and then start the Samba services.

 

Testing the smb.conf File

The settings in the smb.conf file may be tested using the testparm command line tool as follows:

# testparm

Load smb config files from /etc/samba/smb.conf

rlimit_max: rlimit_max (1024) below minimum Windows limit (16384)

Processing section “[homes]”

Processing section “[printers]”

Processing section “[tmp]”

Loaded services file OK.

Server role: ROLE_STANDALONE

Press enter to see a dump of your service definitions

 

[global]

server string = Samba Server Version %v

log file = /var/log/samba/log.%m

max log size = 50

cups options = raw

 

[homes]

comment = Home Directories

read only = No

browseable = No

 

[printers]

comment = All Printers

path = /var/spool/samba

printable = Yes

browseable = No

 

[tmp]

path = /tmp

valid users = demo

read only = No

 

Starting the Samba and NetBIOS Name Services on CentOS 6

In order for a CentOS 6 server to operate within a Windows network both the Samba (SMB) and NetBOIS nameservice (NMB) services must be started. To identify if the services are already running, the following command may be executed with root privileges in a terminal window:

su –

/sbin/service smb status

smbd is stopped

# /sbin/service nmb status

nmbd is stopped

If the services are reported as currently running and you have made changes to the smb.conf file it will be necessary to restart the services in order to pick up the changes:

/sbin/service smb restart

/sbin/service nmb restart

If, on the other hand, the services are currently stopped, start them as follows:

/sbin/service smb start

/sbin/service nmb start

 

Accessing Samba Shares

Now that the Samba resources are configured and the services are running, it is time to access the shared resource from a Windows system. On a suitable Windows system on the same workgroup as the CentOS 6 system, open Windows Explorer and navigate to the Network panel. At this point, explorer should search the network and list any systems using the SMB protocol that it finds.

Leave a Reply

Your email address will not be published. Required fields are marked *