Wednesday, 15 April 2015

Linux & Windows File Sharing Using Samba in RHEL7/CentOS7

This tutorial has the following configuration:
- Samba Server IP Address:    192.168.122.1
- Samba Server Netbios Name: MERUBHAI

- Windows 7 IP Address:         192.168.122.156
- Windows 7 Netbios Name:    SHABBIR-PC

- Windows Workgroup Name: WORKGROUP
- The user account 'shabbir' exists on both linux and windows machines. This account is used for file sharing.


Samba Server Configuration:

NOTE:1) In the Samba config file '/etc/samba/smb.conf', lines starting with ';' or '#' are comments.
           2) All commands are to be run as 'root' user
           3) It is recommended to have the same username & password on both linux and windows machines.

1) Install Samba Server
      yum -y install samba samba-client

2) Edit the Samba config file '/etc/samba/smb.conf'. Make the following changes.

      workgroup = WORKGROUP     /'name of Windows workgroup'
      netbios name = MERUBHAI   /' name of server'
      interfaces = lo eth0 192.168.122.1/24    /'the network interfaces of the server'
      hosts allow = 127. 192.168.122.     /'hosts which are allowed to access the server

     NOTE: Remember to uncomment the above lines by removing the leading ';'

3) Check for config errors
       testparm

4) Create user account
       useradd shabbir
      passwd shabbir

5) Create user in Samba database.
       smbpasswd -a shabbir
       
6) Enable SELinux boolean to allow Samba to access the home directory.
       setsebool -P samba_enable_home_dirs on

7) Create the following public share
       [public]
        comment = Files shared by shabbir
        path = /var/pub/files
        public = yes
        writeable = yes
        printable = no


8) Create directory and create files in the dir.
        mkdir -p /var/pub/files
        touch /var/pub/files/foo{1,2,3,4,5}
        chown -R shabbir:shabbir /var/pub/files

9) Set SELinux file context for the shared directory
       chcon -R -t samba_share_t /var/pub/files

10) Open Firewall Ports.( 137/udp, 138/udp, 139/tcp, 445/tcp)
      firewall-cmd --zone=public --add-service=samba --permanent
      firewall-cmd --reload

11) Start Samba Service and enable on boot
       systemctl start smb
       systemctl start nmb

      systemctl enable smb
      systemctl enable nmb     



Windows Client Configuration:
1)

Open Network and Sharing Center.
Turn on Network Discovery and File Sharing for all public networks OR
Make this network a private network.
   
Click on Network.

2)


Click on MERUBHAI.


3)

Click on public.


4)



NOTE:
1)
To view/change workgroup , right click on My Computer , Select Properties.

2)
To view ip address, type ipconfig in command terminal.

To change ip address, open Network and Sharing Center.
Click on Change Adapter Settings.
Click on Local Area Network.
Click on Properties.
Select Internet Protocol Version 4. Click Properties.Enter IP address.
       
      
View Windows Shared Folders in Linux :


1) View Remote Shares
       smbclient -L 192.168.122.156  -U shabbir    /'windows ip and username'
       Enter shabbir's password:
       Domain=[SHABBIR-PC] OS=[Windows 7 Professional 7601 Service Pack      1]    Server=[Windows 7 Professional 6.1]

    Sharename       Type      Comment
    ---------       ----      -------
    ADMIN$          Disk      Remote Admin
    C$              Disk      Default share
    IPC$            IPC       Remote IPC
    Users           Disk     

2) Create mount point and mount the remote share
       mkdir -p /mnt
      mount //192.168.122.156/Users  /mnt -o username=shabbir,password=pass

3) View shared folder contents
        ls /mnt

         Default  desktop.ini  Public  shabbir


4) Create entry in '/etc/fstab' to automatically mount at boot time.

       //192.168.122.2/Users           /mnt     cifs      rw,username=shabbir,password=pass      0  0

    This is a security risk as '/etc/fstab' is world-readable. So you can configure a dedicated credentials file which is readable only by 'root'.

       //192.168.122.2/Users           /mnt    cifs      rw,credentials=/etc/smbshabbir       0  0


   Create the file '/etc/smbshabbir'
       username=shabbir
      password=pass      

      
   chmod 600 /etc/smbshabbir







No comments:

Post a Comment