sharing files between centos 6 and windows systems with samba.docx

Upload: hongminhxe

Post on 02-Jun-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/10/2019 Sharing Files between CentOS 6 and Windows Systems with Samba.docx

    1/15

    Sharing Files between CentOS 6 and Windows Systems withSambaSamba 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, selectApplications -> 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 theSystem -> Administration -> Firewallmenu

    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.

  • 8/10/2019 Sharing Files between CentOS 6 and Windows Systems with Samba.docx

    2/15

    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 meansthat 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 tools 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 overriddenwithin 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

    http://a.tribalfusion.com/h.click/aQmPKtR6FK4dnM1tMCnH2w3PJQ4sraVcnbWGFfPPZbuWtrWWrj02rimWTQxTTr8PTvZdSVQZbQUItRWniWG3U2rqunten0aen3WbASG7G2mQHodiNUWQ70U7aXbYeXa6oSrBHUbZbSVHJ5mFZbxPrZbr1E3y5qUd2an2oErAYU7fUWJQm6QZdnsnqpHnH5EZb0xLtORa/http:/careerjournaladvisor.com/asia/?sub1=t
  • 8/10/2019 Sharing Files between CentOS 6 and Windows Systems with Samba.docx

    3/15

    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.

  • 8/10/2019 Sharing Files between CentOS 6 and Windows Systems with Samba.docx

    4/15

    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 = Yesbrowseable = 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.conffile 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

  • 8/10/2019 Sharing Files between CentOS 6 and Windows Systems with Samba.docx

    5/15

    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:

    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:

    http://www.techotopia.com/index.php/Image:Centos_6_windows_explorer.png
  • 8/10/2019 Sharing Files between CentOS 6 and Windows Systems with Samba.docx

    6/15

    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:

    http://www.techotopia.com/index.php/Image:Centos_6_windows_accessing.png
  • 8/10/2019 Sharing Files between CentOS 6 and Windows Systems with Samba.docx

    7/15

    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:

    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.

    Installing and configuring samba on centos 6How to install and configure samba on centos 6 :Samba is free software mainly used for file sharing between other platforms ( Windows ) using

    SMB/CIFS protocol .Default centos 6 installation will not include samba packages , you need install

    manually .Here we can see how to install and configure samba using yum.

    http://www.techotopia.com/index.php/Image:Centos_6_samba_windows_workgroup.pnghttp://www.techotopia.com/index.php/Image:Centos_6_samba_windows_network.pnghttp://www.techotopia.com/index.php/Image:Centos_6_samba_windows_workgroup.pnghttp://www.techotopia.com/index.php/Image:Centos_6_samba_windows_network.png
  • 8/10/2019 Sharing Files between CentOS 6 and Windows Systems with Samba.docx

    8/15

    Samba installation :

    After installing Centos 6 (Centos 6 installation step by step screenshots ) and configuring

    network (How to setup network in centos 6)

    Step 1 Update yum repositories and packages by typing the below command

    [root@localhost ~]# yum update

    Step 2 Install samba packages along with dependencies using yum

    [root@localhost ~]# yum install samba

    Samba configuration :

    Step 3 Create a share username and password .

    [root@localhost ~]# useradd shareuser -s /sbin/nologin

    Now create samba password for username shareuser using smbpasswd command .

    [root@localhost ~]# smbpasswd -a shareuser

    New SMB password:****

    Retype new SMB password:****

    Added user shareuser.

    Step 4 Create a folder called share in the root directory .

    [root@localhost ~]# mkdir /share

    and change the ownership for the share folder

    [root@localhost ~]# chown -R shareuser:root /share/

    Step 5 open the file /etc/samba/smb.conf. ( Before editing the file , please copy the

    file to another location for backup ) . Add the below lines at the bottom of the file .

    http://www.krizna.com/centos/centos-6-installation-step-by-step-screenshots/http://www.krizna.com/centos/how-to-setup-network-in-centos-6/http://www.krizna.com/centos/how-to-setup-network-in-centos-6/http://www.krizna.com/centos/centos-6-installation-step-by-step-screenshots/
  • 8/10/2019 Sharing Files between CentOS 6 and Windows Systems with Samba.docx

    9/15

    [share]

    comment = Share

    path = /share

    writable = yes

    valid users = shareuser

    Step 6 start samba service

    [root@localhost ~]# service smb start

    and type this below command to start samba service automatically while booting.

    [root@localhost ~]# chkconfig --levels 235 smb on

    Samba testing :

    Step 7 You can check your configuration by using testparm command

    [root@localhost ~]# testparm

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

    rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)

    Processing section "[homes]"

    Processing section "[printers]"

    Processing section "[share]"

    Loaded services file OK.

    Server role: ROLE_STANDALONE

    Press enter to see a dump of your service definitions

    [global]

    workgroup = MYGROUP

    server string = Samba Server Version %v

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

  • 8/10/2019 Sharing Files between CentOS 6 and Windows Systems with Samba.docx

    10/15

    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

    [share]

    comment = Share

    path = /share

    valid users = shareuser

    read only = No

    You can see your share sections. Here by default home folders of users will be displayed .

    you can comment the unwanted section using ; symbol .

    For example . you can comment homes section as below and restart the service using

    service smb restart

    ;[homes]

    ;comment = Home Directories

    ;read only = No

    ;browseable = No

    Now you can access share folder on windows machine by typing \\samba-server-ip\ on run

    prompt . you can see your share folder after entering username and password.

    Cheers ..

  • 8/10/2019 Sharing Files between CentOS 6 and Windows Systems with Samba.docx

    11/15

    ---------------------------------

    Install and Configure Samba

    [root@lan ~]#

    yum-y install samba

    [root@lan ~]#mkdir/h ome/share

    [root@lan ~]#

    chmod777 /home/share

    [root@lan ~]#

    vi/et c/ samba/ sm b.conf

    # near line 58: add

    unix charset = UTF-8

    dos charset = CP932

    # line 75: change (Windows' default)

    workgroup =

    WORKGROUP

    # line 81: uncomment and change IP address you allow

    hosts allow = 127.

    10.0.0.

    # line 102: change (no auth)

    security =

    share

    # add at the bottom

    [Share]

    # any name you like

    path = /home/share

    # shared directory

    writable = yes

    # writable

    guest ok = yes

    # guest OK

    guest only = yes

    # guest only

    http://www.server-world.info/en/command/html/yum.htmlhttp://www.server-world.info/en/command/html/yum.htmlhttp://www.server-world.info/en/command/html/mkdir.htmlhttp://www.server-world.info/en/command/html/mkdir.htmlhttp://www.server-world.info/en/command/html/chmod.htmlhttp://www.server-world.info/en/command/html/chmod.htmlhttp://www.server-world.info/en/command/html/vi.htmlhttp://www.server-world.info/en/command/html/vi.htmlhttp://www.server-world.info/en/command/html/vi.htmlhttp://www.server-world.info/en/command/html/chmod.htmlhttp://www.server-world.info/en/command/html/mkdir.htmlhttp://www.server-world.info/en/command/html/yum.html
  • 8/10/2019 Sharing Files between CentOS 6 and Windows Systems with Samba.docx

    12/15

    create mode = 0777

    # fully accessed

    directory mode = 0777

    # fully accessed

    share modes = yes

    # warn if some people access to a file

    [root@lan ~]#

    /e tc/ rc .d/ ini t.d /sm b st ar t

    Starting SMB services:

    [ OK ]

    [root@lan ~]#

    /e tc/ rc .d/ ini t.d /n mb st ar t

    Starting NMB services:

    [ OK ]

    [root@lan ~]#

    chkconfigsmb on

    [root@lan ~]#

    chkconfignmb on

    -------------------------------

    I'm using Cent OS 5.3 as the lab server. FTP is not so easy to use, so Idecide to set up Samba service.

    STEP 1Install the samba from YUM update.view plaincopy to clipboardprint?

    1. [root@sample ~]# yum -y install samba

    STEP 2

    Edit the configure fileview plaincopy to clipboardprint?

    1. [root@sample ~]# vi /etc/samba/smb.conf

    There are several places to modify.1st place (We must use Chinese so I use GB2312 as charset):

    view plaincopy to clipboardprint?

    1. [global]2. dos charset = GB23123. unix charset = GB23124. display charset = GB23125. directory mask = 0777

    http://www.server-world.info/en/command/html/chkconfig.htmlhttp://www.server-world.info/en/command/html/chkconfig.htmlhttp://www.server-world.info/en/command/html/chkconfig.htmlhttp://www.server-world.info/en/command/html/chkconfig.htmlhttp://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://www.server-world.info/en/command/html/chkconfig.htmlhttp://www.server-world.info/en/command/html/chkconfig.html
  • 8/10/2019 Sharing Files between CentOS 6 and Windows Systems with Samba.docx

    13/15

    6. force directory mode = 07777. directory security mask = 07778. force directory security mode = 07779. create mask = 077710.force create mode = 077711.security mask = 077712.force security mode = 0777

    2nd PlaceChange the following line

    1. workgroup = MYGROUP

    into

    1. workgroup = WORKGROUP

    3rd Place, add IP address which is allowed to access the service.

    view plaincopy to clipboardprint?

    1. hosts allow = 192.168.0. 127.

    4th Place, in the end of the file, add:

    1. [public]2. comment = Public Stuff3. path = /data/public_dir4. public = yes5. writable = yes

    STEP 3Set up the public folder and provide sufficient privilege.view plaincopy to clipboardprint?

    1. [root@sample ~]# mkdir /data/public_dir2. [root@sample ~]# chown -R nobody. /data/public_dir

    3. [root@sample ~]# chmod 777 /data/public_dir

    STEP 4Add samba users (Make sure that the user you are adding has already been alinux system user). Here I take user goodcjwas an example.view plaincopy to clipboardprint?

    1. [root@sample ~]# smbpasswd -a goodcjw

    STEP 5Take care of your firewall. You should configure your iptables to open port

    139 and 445.STEP 6Make Samba suns once the system starts up.view plaincopy to clipboardprint?

    1. [root@sample ~]# chkconfig smb on2. [root@sample ~]# chkconfig --list smb3. smb 0:off 1:off 2:on 3:on 4:on 5:on 6:off

    Start up Samba service.

    http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71
  • 8/10/2019 Sharing Files between CentOS 6 and Windows Systems with Samba.docx

    14/15

    view plaincopy to clipboardprint?

    1. [root@sample ~]# /etc/rc.d/init.d/smb start2. Starting SMB services: [ OK ]

    3. Starting NMB services: [ OK ]

    STEP 7Now, all works are done. Use one windows PC to map the shared folder

    provided by Samba.------------------

    Configuring a Samba Server (windows file server)1.Check the necessary rpm

    #rpm -q samba

    2.set the samba work group name according to windows work group or domain name.

    #nano /etc/samba/smb.conf

    Press CTRL + W

    Search >>>> mygroup

    delete the mygroup and type your windows work group or domain name

    3.Start the samba service

    #service smb start

    #chkconfig smb on

    4.Now you will be able to see the samba servers through my network places in windows, but you wont be

    able to access them unless you create samba user accounts in linux.

    5.You must have a Linux user account first

    #useradd uddika

    #passwd uddika

    6.you can convert them in to samba

    #smbpasswd -a uddika

    you can use user current password or another one.

    7.Once you add a user to samba his home folder will be automatically shared. How to share a different

    folder through samba.

    8.Create a folder to share

    http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71http://blog.jiwen.info/?p=71
  • 8/10/2019 Sharing Files between CentOS 6 and Windows Systems with Samba.docx

    15/15

    #cd /

    #mkdir test

    9.sharing above folder through samba

    #nano /etc/samba/smb.conf

    Go to a end of file, to a new line

    [MyTestShare]

    path = /test

    public = yes

    writable = yes

    10.Save and exit the file

    CTRl + OCTRL + X

    11.Reload the samba service

    #service smb reload

    12.Although we give a writable samba permissions, normal samba users wont be able to witting to the

    folder though windows, unless we change the ext3 file folder permissions properly.

    13.See current permissions

    #cd /

    #ls -ld test

    14.Change current permissions

    #chmod 757 test

    #ls -ld

    now normal users can access share folder