Sharing Files between RHEL 6 and Windows Systems with Samba

Samba and Samba Client

Samba allows both RHEL resources to be shared with Windows systems and Windows resources to be shared with RHEL systems. RHEL accesses Windows resources using a package named samba-client. RHEL 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 you to browse available Windows resources without any additional work (this is covered later in the chapter). In order to allow an RHEL 6 system to share resources with Windows systems, however, some more work is required.

Installing Samba on an RHEL 6 System

The default settings used during the RHEL 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 RHEL Firewall to Enable Samba

Next, the firewall currently protecting the RHEL 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 RHEL system can be accessed from the Windows systems, however, some additional configuration steps are necessary.

Configuring the smb.conf File

In releases of Red Hat Enterprise Linux prior to release 6, a user friendly graphical tool named system-config-samba was provided to assist in the configuration of Samba. In RHEL 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 tasking 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 an RHEL 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 RHEL 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 RHEL 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 RHEL 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 RHEL 6

In order for an RHEL 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 RHEL 6 system, open Windows Explorer and navigate to the Network page. At this point, explorer should search the network and list any systems using the SMB protocol that it finds. The following figure illustrates an RHEL 6 system named rhel6 located using Windows Explorer on a Windows 7 system:
Accessing an RHEL 6 system from a Windows 7 desktop
Double clicking on the RHEL 6 host will prompt for the name and password of a user with access privileges. In this case it is the demo account that we configured using the smbpasswd tool. Entering the username and password will result in the shared resources configured for that user appearing the explorer window, including the tmp resource previously configured:
RHEL 6 shares listed on Windows 7
Double clicking on the tmp shred resource will display a listing of the files and directories contained therein.

Accessing Windows Shares from RHEL 6

As previously mentioned, Samba is a two way street, allowing not only Windows systems to access files and printers hosted on an RHEL 6 system, but also allowing the RHEL system to access shared resources on Windows systems. This is achieved using the samba-client package which is installed by default under most RHEL 6 configurations. If it is not currently installed, install it from a Terminal window as follows:

su –
yum install samba-client

To access any shared resources on a Windows system, begin by selecting the Places -> Network desktop menu option. This will display the Network browser dialog including an icon for the Windows Network (if one is detected) as illustrated in the following figure:
Image:rhel6_windows_network_in_nautilus.jpg
To obtain a list of Windows workgroups on the network, double click on the Windows Network icon. From within the list of workgroups double click on the desired group to obtain a listing of servers available for access:

Image:rhel6_samba_windows_resources.jpg
Finally, double clicking on a computer will list the shared resources available for access from the RHEL client.

Summary

In this chapter we have looked at the steps necessary to configure an RHEL 6 system to act as both a Samba client and server allowing the sharing of resources with other systems on a Windows based network. In the case of Samba server configuration in particular we have only scratched the surface of the configuration options available. A full over of Samba would require an entire book. Many such publications and online resources are available if you would like to learn more. Another good place to start is to type man samba in a

terminal window.

Requirements for Configuring an RHEL 6 Web Server

To set up your own web site you need a computer, an operating system, a web server, a domain name, a name server and an IP address.

The computer can be any system capable of running Linux. In terms of an operating system, we will, of course, assume you are using RHEL 6. As previously mentioned RHEL supports the Apache web server which can easily be installed once the operating system is up and running. A domain name can be registered with any domain name registration service.

If your ISP provides static IP addresses then you will need to associate your domain with your static IP address. This is achieved using a name server. Most domain registration services will provide this service for you.

If you do not have a static IP address (i.e. your ISP provides you with a dynamic address which changes frequently) then you can use one of a number of free services which map your dynamic IP address to your domain name. One such service is provided by http://www.dnsExit.com.

Once you have your domain name and your name server configured the next step is install and configure your web server.

Installing the Apache Web Server on RHEL 6

The current release of RHEL typically does not install the Apache web server by default. To check whether the server is already installed, open a Terminal window (Applications -> System Tools -> Terminal) and run the following command:

rpm -q httpd

If rpm generates output similar to the following, the apache server is already installed:

httpd-2.2.15-5.el6.x86_64

Alternatively, if rpm generates a “package httpd is not installed” then the next step, obviously, is to install it. This can be performed either from the command-line or using the Add/Remove Software tool. To use this tool, open the System -> Administration desktop menu and select Add/Remove Software. Enter your root password if prompted to do so. Select the Search tab and search for httpd. After the search completes the Apache HTTP Server should be listed in the search results. Click on the toggle next to the httpd server. Finally, click on the Apply button to begin the installation.

To install Apache from the command-line start a terminal window (Applications -> System Tools -> Terminal) and run the following commands at the command prompt:

su -
yum install httpd

Starting the Apache Web Server

Once the Apache server is installed, the next step is to verify that the server is running and, if it is not yet running, to start it.

The status of the server can be verified from the command-line or via the GUI Service Configuration tool. To check the status of the Apache httpd service from the command-line, enter the following command in a Terminal window:

/sbin/service httpd status

If the above command indicates that the httpd service is not running, it can be launched from the command-line as follows:

su -
/sbin/service httpd start

If you would like the Apache httpd service to start automatically when the system boots (for example when booting to runlevel 3), this can be achieved by running the following command:

/sbin/chkconfig --level 3 httpd on

For more information on runlevels refer to the chapter entitled Configuring RHEL 6 Runlevels and Services.

To configure the Apache service using the Service Configuration tool, select the System -> Administration -> Services menu option and scroll down the list of services until you find httpd. Select the item in the list and click on the Start button.

Testing the Web Server

Once the installation is complete the next step is to verify the web server is up and running. To do this fire up the web browser by clicking on the web browser icon in the top desktop panel and enter 127.0.0.1 in the address bar (127.0.0.1 is the loop-back network address which tells the system to connect to the local machine). The browser should load the Red Hat Enterprise Linux Test Page:
The RHEL 6 Apache test web page
Congratulations, you have now installed the web server and served up what will hopefully be the first of many web pages.

Configuring the Apache Web Server for Your Domain

The next step in setting up your web server is to configure it for your domain name. This is performed in the /etc/httpd directory. To configure the web server open a terminal window and change directory to /etc/httpd. In this directory you will find a number of sub-directories. Change directory into the conf sub-directory where you will find an httpd.conf file which contains the configuration settings for the Apache server.

Edit the httpd.conf file using your favorite editor using the su command to ensure you have write permission to the file. Once loaded, there are a number of settings that need to be changed to match your environment.

The ServerAdmin directive defines an administrative email address for people wishing to contact the webmaster for your site. Change this to an appropriate email address where you can be contacted:

ServerAdmin webmaster@myexample.com

Next the ServerName and ServerAlias directives need to be defined so that the web server knows which virtual host this configuration file refers to:

ServerName myexample.com

Next, we need to define where the web site files are going to be located using the DocumentRoot directive. The tradition is to use /var/www/domain-name:

DocumentRoot /var/www/myexample.com

Next, create the /var/www/myexample.com directory and place an index.html file in it. For example:

<html>
<title>Sample Web Page</title>
<body>
Welcome to MyExample.com
</body>
</html>

The last step is to restart the apache web server to make sure it picks up our new settings:

su - 
/sbin/service httpd restart

Web Server and Firewall Issues

If your RHEL 6 system is configured to use a firewall, you will need to ensure that HTTP traffic on port 80 is permitted in order for external systems to be able to access your web server. Refer to Basic RHEL 6 Firewall Configuration for details on configuring RHEL Firewalls.

If the RHEL 6 system hosting your web server sits on a network protected by a firewall (either another computer running a firewall, or a router or wireless base station containing built in firewall protection) you will need to configure the firewall to forward port 80 to your web server system. The mechanism for performing this differs between firewalls and devices so check your documentation to find out how to configure port forwarding.

Once everything is configured it should be possible to enter the domain name of your web site into a browser anywhere in the world and access your web server.

Advertisements
%d bloggers like this: