Difference between revisions of "Sharing Files between CentOS 6 and Windows Systems with Samba"

From Techotopia
Jump to: navigation, search
m (Text replacement - "<google>ADSDAQBOX_FLOW</google>" to "<htmlet>adsdaqbox_flow</htmlet>")
m (Text replacement - "<google>BUY_CENTOS6</google>" to "<htmlet>centos6</htmlet>")
Line 8: Line 8:
  
  
<google>BUY_CENTOS6</google>
+
<htmlet>centos6</htmlet>
  
  
Line 217: Line 217:
  
  
<google>BUY_CENTOS6</google>
+
<htmlet>centos6</htmlet>
  
  

Revision as of 21:39, 1 February 2016

PreviousTable of ContentsNext
Using NFS to Share CentOS 6 Folders with Remote Linux and UNIX SystemsConfiguring a CentOS 6 Based Web Server


You are reading a sample chapter from the CentOS 6 Essentials Essentials book.

Purchase a copy of the fully updated CentOS 8 edition in eBook ($24.99) or Print ($36.99) format

CentOS 8 Essentials Print and eBook (ePub/PDF/Kindle) editions contain 31 chapters and over 260 pages. Learn more...

Buy Print Preview Book


Although Linux is increasingly making inroads into the desktop market, its origins are very much server based. It is not surprising therefore that CentOS 6 has the ability to act as a file server. It is also extremely common for CentOS and Windows systems to be used side by side in networked environments. It is a common requirement, therefore, that files on a CentOS 6 system be accessible to Linux, UNIX and Windows based systems over network connections. Similarly, shared folders and printers residing on Windows systems must also be accessible from CentOS based systems.

Windows systems share resources such as file systems and printers using a protocol called Server Message Block (SMB). In order for a CentOS 6 system to serve such resources over a network to a Windows system and vice versa it must, therefore, support SMB. This is achieved using technology called Samba. In addition to providing integration between Linux and Windows systems, Samba may also be used to provide folder sharing between Linux systems (as an alternative to NFS which was covered in the previous chapter).

In this chapter we will look at the steps necessary to share file system resources and printers on a CentOS 6 system with remote Windows and Linux systems.


Contents


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. The following figure illustrates a CentOS 6 system named CentOS6 located using Windows Explorer on a Windows 7 system:


Accessing CentOS 6 resources from Windows using Samba


Double clicking on the CentOS 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:


Accessing Samba Servers from Windows


Double clicking on the tmp shared resource will display a listing of the files and directories contained therein.

Accessing Windows Shares from CentOS 6

As previously mentioned, Samba is a two way street, allowing not only Windows systems to access files and printers hosted on a CentOS 6 system, but also allowing the CentOS system to access shared resources on Windows systems. This is achieved using the samba-client package which is installed by default under most CentOS 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:


Accessing Windows networks from CentOS 6 using Samba


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:


Accessing Windows systems from CentOS 6 using Samba


Finally, double clicking on a computer will list the shared resources available for access from the CentOS client.

Summary

In this chapter we have looked at the steps necessary to configure a CentOS 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.


You are reading a sample chapter from the CentOS 6 Essentials Essentials book.

Purchase a copy of the fully updated CentOS 8 edition in eBook ($24.99) or Print ($36.99) format

CentOS 8 Essentials Print and eBook (ePub/PDF/Kindle) editions contain 31 chapters and over 260 pages. Learn more...

Buy Print Preview Book



PreviousTable of ContentsNext
Using NFS to Share CentOS 6 Folders with Remote Linux and UNIX SystemsConfiguring a CentOS 6 Based Web Server