Search This Blog

Sunday 21 April 2019

Samba Server


1. What is Samba  and  explain it?
(i)    An open source implementation of the SMB file sharing protocol that provides file and                       print services to SMB/CIFS clients. 
               Samba allows a non-Windows server to communicate with the same networking protocol as                 the Windows products.
(ii)  Samba allows Linux computers to share files and printers across a network connection by                   using  SMB protocol. 
               Samba will support  DFS, NFS,  ufs  file systems to share files and directories. That's why                   Samba  is used to share files and directories between different platforms.
(iii) Samba will support printer sharing and it requires authentication.

2. What are the differences between  Samba   and  NFS?
(i) Samba supports to all O/S  platforms,  whereas  NFS will support the some platforms only. 
(ii) There is a security in Samba because  Samba requires authentication,  whereas  in  NFS                        there is no security if there is no kerberos because  NFS does not requires authentication.
(iii) Samba will support printer sharing,  whereas  NFS  will not support printer sharing.

3. What are the different file systems for sharing different  O/S?
(i) Windows         ---   Windows            ----->   Distributed  File system  (DFS)
(ii) Linux               ---  Linux                  ----->   Network File system  (NFS)
(iii) Unix             ---   Unix                  ----->   Network File system  (NFS)
(iv) Apple  MAC    ---   Apple  MACs    ----->  Apple  File sharing  Protocol  (AFP)
(v) Windows          ---   Linux                ----->   Common  Internet  File  system  (CIFS)

4. What are the requirements  or  what is the profile of  Samba?
(i) Packages : samba*  for  samba server  and  samba-client*  for  samba client
(ii) Deamons : -smbd  and  nmbd   for  RHEL - 6  where as  smbd  is for Samba server                                                   deamon and nmbd  is for Netbios  service  deamon.
-smb  and  nmb  for  RHEL - 7  where as  smb  is for Samba server deamon                                            and is for Netbios  service deamon.
(iii) Scripting  files : /etc/init.d/smb     and   /etc/init.d/nmb
(iv) Port  number : 137  --->  to verify the share name,   138  --->  to data transfer,   
139  --->  to connection establish  and   445  --->  for  authentication
(v) Log file : /var/log/samba
(vi) Configuration : /etc/samba/smb.conf
(vii) File systems : CIFS  (Common  Internet  File system)

5. How to configure the  Samba  server?
(i) Install  the  samba package by   # yum  install  samba*   -y    command.
(ii) Create  a  samba shared directory by   # mkdir    /samba    command.
(iii) Modify the permissions of the above samba shared directory.
# chmod    777   /samba
(iv) Modify the SELinux  context  of the samba directory if  SELinux is enabled.
# chcon    -t    samba_share_t    /samba
(v) Create the samba user  and  assign the password for the samba user.
# useradd     raju  (to create the samba user)
# smbpasswd    -a    raju  (to assign the samba password for the user raju)
(vi) Assign the  ACL  permissions  (like  read,  write  and  execute)  to the above shared                            directory if it is necessary.
# setfacl    -m   u : <user name> : rwx   <samba  shared  name>
Example :  # setfacl     -m   u:raju:rwx    /samba
(vii) Open the samba configuration file  and  put an entries of the Samba configuration.
# vim   /etc/samba/smb.conf
Go to last  line and copy the last  7 lines  and  paste them at last. And then modify as below.
[samba] (this is the samba shared name)
comment = public stuff (this is a comment for samba)
path = /samba (share directory name with full path)
                public  =  yes (means  no authentication)
    =  no (means requires authentication)
writable = yes (in read-write mode)
              = no (in read only mode)
printable = no (printing is not available)
       = yes (printing is available)
write list = raju  (to give the write permission to user raju)
= + <group name> (to give the write permission to the group)
valid users = raju, u2
                 or  @group 1, @group 2 (to give the authentication to the users or  groups)
         hosts allow = IP 1  or  IP 2  
                 or  host 1  or  host2 
                  or  <host  network  ID>  or  <host  network  ID>
                                                                   (to share the directory to IP 1  or  IP 2  or  host 1  or  host2)
work group = <windows  work group  name>
                                                                   (to share the directory to the windows work group)
create mask = 644  (the files created by samba users with  644 permission) 
directory mask = 744  or  755 (the directories created by samba users with  744  or  755                                                                             permissions) 
(save  and  exit  the  configuration  file)
(viii) Verify  the configuration file  for  syntax  errors  by   # testparm    command.
(ix) Restart the samba deamons in RHEL - 6  and  RHEL - 7.
# service  smbd  nmbd  restart(to restart the samba services  in  RHEL - 6)
# chkconfig  smbd  nmbd  on (to enable the samba services at next boot  in  RHEL - 6)
# systemctl  restart  smb  nmb(to restart the samba services  in  RHEL - 7)
# systemctl  enable  smb  nmb(to enable the samba services at next boot  in  RHEL - 7)
(x) Add the samba service to  IP tables  and  Firewall.
# setup(then select Firewall configuration option to add the service to IP tables  in  RHEL - 6)
# service  iptables  restart(to restart the  IP tables  in  RHEL - 6)
# firewall-cmd   --permanent   --add-service=samba(to add the samba service to firewall  in                                                                                                                                      RHEL - 7)   
       # firewall-cmd    --complete-reload (to reload the firewall  in RHEL - 7)

6. How to access the samba share directory at client side?
(i) Install  client side  samba packages  by   # yum  install  samba-client*   cifs-utils     -y                          command.
(ii) Check the samba shared directory names from client side.
# smbclient  -L   //<host name  or  IP address of the server>
          (then it will ask password, here don't enter any password because it does not require any                                                                                                                                                 password)
Example :# smbclient    -L   //server9.example.com   or  172.25.9.11
(iii) connect the samba server with user credentials and access the samba shared directory.
# smbclient     //<host name  or  IP address of the server>/<shared directory name>    -U    <samba user name>(Where  U  is Capital  Letter  and  we have to enter the user's  samba password)
Example : # smbclient    //server9.example.com/samba   -U   raju     (then   smb :/>   prompt  appears)
smb:/> ls (to see the contents of the samba shared directory)
smb:/> pwd (to see the present working directory)
smb:/> ! ls (to see the client's  local directory contents)
smb:/> get  <file name> (to download the specified file from samba server)
smb:/> mget   <file 1><file 2><file 3>(to download multiple  files from samba server)
smb:/> put   <file name>       (to upload the specified file to the samba server)
smb:/> put   <file 1><file 2><file 3>   (to upload multiple files to the samba server)
smb:/> exit (to exit from the samba server)

7. How to mount the samba shared directory permanently?
(i) Create the mount point for the samba shared directory.
# mkdir   /mnt/samba
(ii) Put an entry of the mount point details in  /etc/fstab   file.
# vim   /etc/fstab
 //<samba server host name  or  IP address>/<shared directory name><mount point>   cifs                          defaults ,username=<samba user name>, password=<user's  samba password>    0    0

Example :   //server9.example.com/samba      /mnt/samba     cifs   defaults, username=raju,      password=<samba password>     0    0       (save  and  exit  this  file)
(iii) Mount all the mount points which are having entries in  /etc/fstab    file.
# mount    -a
(iv) Check all the mount points  by   # df   -hT    command.

8. How to mount the samba shared directory using credential file?
(i) Create  one file and put an entries of the user name and password details.
# vim   /root/smbuser
  username=raju
  password=<user's  samba  password> (save  and  exit  the  file)
(ii) Open  /etc/fstab   file  and  put an entries of the above credential details of user.
# vim  /etc/fstab
//server9.example.com/samba  /mnt/samba  cifs  credentials=/root/smbuser,  multiuser,                          sec=ntlmssp   0    0  (save  and  exit  this  file)

9. How to access the samba share directory if it already mounted?
(i) Go to Client system and switch to samba user.
# su   -  raju
$ cd   /mnt/samba
$ ls (permission denied message will be displayed)
$ cifscreds   add   <host name  or  IP address of the samba server>
                                                                                (to add  cifs  credentials to the server)
$ ls (to see the contents of the samba shared directory)

10. How to access the samba server from  windows system?
(i) Goto Windows system,  click on  START  button,  click on  Run  and  type  as                                        \\172.25.9.11\samba command.
(ii) Then  provide  samba user name  and  password  if it prompts us.
(iii) Then see the contents of the samba shared directory.
Other  useful  commands :
# smbpasswd     -a   <user name> (to add the samba password to the samba user)
# smbpasswd     -d    <user name> (to disable the samba user's  password)
# smbpasswd     -e    <user name> (to enable the samba user's  password)
# smbpasswd     -r    <user name> (to remove the samba user's  password)
# smbpasswd     -x    <user name> (to delete the samba user's  password)
# smbpasswd     -n    <user name> (to set the samba user's  password as  null)
# findsmb        (to check how many samba servers are running in our network)
# pdbedit        (to check the available samba users who are accessing currently)
# smbstatus        (to check how many smb clients are connected to the samba server)
# mount   -t   cifs   //<host name  or  IP address of the samba server>/<shared direcotory>                      <mount point>  -o  user=<user name>          
                                                  (to mount the samba share directory on local mount point temporarily)

Example :   # mount   -t   cifs   //172.25.9.11/samba    /mnt/samba    -o   user=raju

No comments:

Post a Comment