Wednesday, June 27, 2018

Install Samba on Centos 7 for file sharing on Windows

Description: In this article I have explain how we can sharing files between windows and Centos

Procedure: 

  • Install Samba in Centos 7 using below command
# yum install samba samba-client samba-common
  • After installation need to add in firewall 
# firewall-cmd --permanent --zone=public --add-service=samba
# firewall-cmd --reload
  • Check windows system work group settings. Before configure samba need to check work group in windows PC.  We can check from My Computer -- Properties -- Advance System settings -- Computer Name
  • After checking work group configure Samba on centos 7. The configuration file of samba is /etc/samba/smb.conf  with pre-configuration settings. But make sure to take backup before made any changes. 
  • First create any directory that you want to share like "Testdirectory"  and set appropriate permission on it.
# mkdir -p /srv/samba/Testdirectory
# chmod -R 0775 /srv/samba/Testdirectory
# chown -R nobody:nobody /srv/samba/Testdirectory
  • You need to set SELinux security context for shared directory
# chcon -t samba_share_t /srv/samba/Testdirectory
  • After creating directory open smb configuration directory and add as following 
# useradd authuser
# vi /etc/samba/smb.conf
[global]
workgroup = WORKGROUP
netbios name = centos
security = user

[Testdirectory]
comment = Test Directory
path = /srv/samba/Testdirectory
browsable =yes
writable = yes
guest ok = yes
read only = no
force user = nobody
  • Now test configuration using below command 
# useradd authuser
# 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 "[print$]"
Processing section "[Anonymous]"
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions
# Global parameters

[global]
netbios name = centos
printcap name = cups
security = USER
idmap config * : backend = tdb
cups options = raw

[homes]
comment = Home Directories
browseable = No
inherit acls = Yes
read only = No
valid users = %S %D%w%S

[printers]
comment = All
Printers
path = /var/tmp
browseable = No
printable = Yes
create mask = 0600
[print$]
comment = Printer
Drivers
path = /var/lib/samba/drivers
create
mask = 0664
directory mask = 0775
write list = root
[Testdirectory]
comment = Anonymous File Server Share
path = /srv/samba/Testdirectory
force user = nobody
guest ok = Yes
read only = No
  • Now start samba service and enable it during boot process
# systemctl enable smb.service
# systemctl enable nmb.service
# systemctl start smb.service
# systemctl start nmb.service
  • Now test from your windows client by using \\ipaddress_of_server 
Setup Secure Samba in Centos 7 
  • First create samba group, then add user and set password for them.
# groupadd smbgrp
# usermod systalk -aG smbgrp
# smbpasswd -a systalk
  • Then create a secure directory where the shared files will be kept and set the appropriate permissions on the directory with SELinux security context for the samba.
# mkdir -p /srv/samba/secure
# chmod -R 0770 /srv/samba/secure
# chown -R root:smbgrp /srv/samba/secure
# chcon -t samba_share_t /srv/samba/secure
  • Open samba configuration file and add samba group for appropriate sharing 
# vi /etc/samba/smb.conf
[Secure]
comment = Secure File Server Share
path =  /srv/samba/secure
valid users = @smbgrp
guest ok = no
writable = yes
browsable = yes
  • After configuration run testparm to test configuration and restart service 
# systemctl restart smb.service
# systemctl restart nmb.service
  • Now test secure samba file sharing it will prompt for password. 

No comments:

Post a Comment