Installing Samba Server and Mapping Shares from Windows To CentOS

SAMBA
NFS=network file sharing (linux, unix) windows can also work with nfs
SMB= server message block (windows) with samba linux can work with smb
File and printer sharing using SMB

NFS EXPORT = SMB SHARE
NFS MOUNT = SMB MAP

smb= CIFS= common internet file system

Install samba

Check if samba is installed

[root@samba ~]# yum list samba
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Available Packages
samba.x86_64                                           3.6.23-20.el6                                           base

Install samba if not installed

[root@samba ~]# yum install samba
Dependencies Resolved

===================================================================================================================
 Package                              Arch                  Version                      Repository           Size
===================================================================================================================
Installing:
 samba                                x86_64                3.6.23-20.el6                base                5.0 M
Updating for dependencies:
 libsmbclient                         x86_64                3.6.23-20.el6                base                1.6 M
 samba-client                         x86_64                3.6.23-20.el6                base                 11 M
 samba-common                         x86_64                3.6.23-20.el6                base                 10 M
 samba-winbind                        x86_64                3.6.23-20.el6                base                2.2 M
 samba-winbind-clients                x86_64                3.6.23-20.el6                base                2.0 M

 

Start samba service and Make it always start at boot time with ckhconfig

[root@samba ~]# service smb start
Starting SMB services:                                     [  OK  ]
[root@samba ~]# chkconfig smb on

 

Lets Create a samba share

we will create a folder called /share-for-samba

and create a file called samba.txt

[root@samba ~]# mkdir /share-for-samba
[root@samba ~]# cd /share-for-samba/
[root@samba share-for-samba]# echo "this is a test file for samba tutorial" >> samba.txt
[root@samba share-for-samba]# cd  /
[root@samba /]# ls -ld /share-for-samba/
drwxr-xr-x 2 root root 4096 Sep 28 21:36 /share-for-samba/

Note above owner of /share-for-samba is root and group ownership is root

We will have to create a user and give ownership of the folder to that user

[root@samba /]# useradd demosmbuser
[root@samba /]# passwd demosmbuser
Changing password for user demosmbuser.
New password:
BAD PASSWORD: it is based on your username
Retype new password:
passwd: all authentication tokens updated successfully.

Now change the owner and group owner of the folder to demosmbuser

[root@samba /]# chown -R demosmbuser:demosmbuser /share-for-samba/
[root@samba /]# ls -ld /share-for-samba/
drwxr-xr-x 2 demosmbuser demosmbuser 4096 Sep 28 21:36 /share-for-samba/

 

Now lets create samba user for demosmbuser with smbpasswd comand

[root@samba /]# smbpasswd -a demosmbuser
New SMB password:
Retype new SMB password:
Added user demosmbuser.

The above comand will create a samba user called demosmbuser and put it in a samba database

Verify the user with pdbedit command

[root@samba /]# pdbedit -L
demosmbuser:500:

just press pdbedit to get help for the command

Lets configure a Share

Configuration file for samba is

vi    /etc/samba/smb.conf

go the the file and skip to the section that says

#============================ Share Definitions ==============================

[homes]
        comment = Home Directories
        browseable = no
        writable = yes
;       valid users = %S
;       valid users = MYDOMAIN\%S

[printers]
        comment = All Printers
        path = /var/spool/samba
        browseable = no
        guest ok = no
        writable = no
        printable = yes

add the following to add share for our /share-for-samba directory just below printers

[samba-share]
            comment = demo share for samba
            path = /share-for-samba
            read only = no
            guest ok = yes

we can also check the changes in smb.conf by using testparm command

[root@samba ~]# 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 "[samba-share]"
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions

Lets restart the service and check the settings with smbclient command

[root@samba ~]# service smb reload
Reloading smb.conf file:                                   [  OK  ]

[root@samba ~]# smbclient -L localhost -U demosmbuser
Enter demosmbuser's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.6.23-20.el6]

        Sharename       Type      Comment
        ---------       ----      -------
        samba-share     Disk      demo share for samba
        IPC$            IPC       IPC Service (Samba Server Version 3.6.23-20.el6)
        demosmbuser     Disk      Home Directories
Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.6.23-20.el6]

        Server               Comment
        ---------            -------

        Workgroup            Master
        ---------            -------

 

Samba server runs on port

tcp/udp   = 137,138,139 and 445

so open it if you have iptables running

===========================================================================

 

Samba Client SETUP

check if client for samba is installed or not

[root@sambaclient ~]# yum list samba-client
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: centos.host-engine.com
 * extras: centos.host-engine.com
 * updates: centos.host-engine.com
Installed Packages
samba-client.x86_64                                    3.6.23-14.el6_6                                     @updates
Available Packages
samba-client.x86_64                                    3.6.23-20.el6                                       base

Looks like samba client is installed if not installed install it with

[root@sambaclient ~]# yum install samba-client

Things to note

sambaserver == 10.0.0.74

samba user == demosmbuser

sambashare == samba-share with path /share-for-samba

sambaclient == 10.0.0.211

now since samba client is installed, lets check shares from samba server 10.0.0.74 with smbclient command

[root@sambaclient ~]# smbclient -L 10.0.0.74 -U demosmbuser
Enter demosmbuser's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.6.23-20.el6]

        Sharename       Type      Comment
        ---------       ----      -------
        samba-share     Disk      demo share for samba
        IPC$            IPC       IPC Service (Samba Server Version 3.6.23-20.el6)
        demosmbuser     Disk      Home Directories
Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.6.23-20.el6]

        Server               Comment
        ---------            -------

        Workgroup            Master
        ---------            -------

Now lets create a mount point called /sambamount

and mount temporarly with mount command,

[root@sambaclient ~]# mkdir /sambamount
[root@sambaclient ~]# mount -t cifs -o user=demosmbuser    //10.0.0.74/samba-share /sambamount
Password:
[root@sambaclient ~]# ls -l /sambamount
total 4
-rw-r--r-- 1 500 500 39 Sep 28 21:36 samba.txt

Here above,

-t cifs = denotes filesystem type is cifs (smb file system)

-o user=demosmbuser   =  samba user must be given in order to mount the share,

double check if the share is mounted

[root@sambaclient ~]# mount -t cifs
//10.0.0.74/samba-share on /sambamount type cifs (rw)

Mount cifs share permanently from /etc/fstab file

first create a file to put username and password in it for authentication

[root@sambaclient ~]# vi /root/.smbcredentails
username=demosmbuser
password=password

then change the permossion of the file

[root@sambaclient ~]# chmod 600 .smbcredentails

now put mount information in /etc/fstab file

[root@sambaclient ~]# vi /etc/fstab
//10.0.0.74/samba-share /sambamount cifs credentials=/root/.smbcredentails,iocharset=utf8,sec=ntlm 0 0

now mount it

[root@sambaclient ~]# mount -a
[root@sambaclient ~]# ls -l /sambamount/
total 4
-rw-r--r-- 1 500 500 51 Sep 28 22:38 samba.txt

 

 

For Trouble shooting purpose

All logs files are kept in /var/log/samba of SambaServer

Mount the share to windows machine

  1. click on my computer and right click on Network the click on map network device

samba-share-windows1

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

2) Then select the drive and put the ipaddress or hostname and name of the share (please note name of the share and path of the share might be different , depends on how it is set in samba server) for example the name of our share is samba-share but the real path is /share-for-samba, to verify u can do  smbclient -L 10.0.0.74 -U demosmbuser and check sharename section

samba-share-windows2

 

 

 

 

 

 

 

 

 

 

 

3)Now put samba username and password

samba-share-windows3

 

 

 

 

 

 

 

 

4)Now you can access the share and can write or read the file in it or add more files of your own

samba-share-windows4

 

 

 

 

5)you can also put it into your browser

samba-share-windows5

Leave a Reply