Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Running Samba Inside CentOS 7

DZone's Guide to

Running Samba Inside CentOS 7

A tutorial for running Samba inside the CentOS guest to access folders in the running CentOS guest from a Windows 7 host system.

· DevOps Zone
Free Resource

The Nexus Suite is uniquely architected for a DevOps native world and creates value early in the development pipeline, provides precise contextual controls at every phase, and accelerates DevOps innovation with automation you can trust. Read how in this ebook.

This was a problem puzzling me a complete day. My environment is as follows:

  • Running Windows 7 (64 Bit)
  • Using VirtualBox 5 to run CentOS 7 as Linux guest

I was looking for a solution to create a Samba share inside the CentOS guest, so I am able to access folders in the running CentOS guest from my Windows 7 host system.

I configured VirtualBox to use two network adapters (NAT and Host-Only).

I installed Samba on the CentOS guest and configured it as a Standalone Server. I created a Samba share called "data". See the full smb.conf here, the Samba share is defined at the end of the file:

 [global]  
      workgroup = WORKGROUP  
      server string = Samba Server Version %v  
      dns proxy = no  
      # log files split per-machine:  
      log file = /var/log/samba/log.%m  
      # maximum size of 50KB per log file, then rotate:  
      max log size = 50  
      security = user  
      passdb backend = tdbsam  
      load printers = yes  
      cups options = raw  
      server role = standalone server  
      encrypt passwords = true  
      guest ok = yes  
      usershare allow guests = yes  
      obey pam restrictions = yes  
      unix password sync = yes  
      passwd program = /usr/bin/passwd %u  
      passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .  
      pam password change = yes  
      map to guest = bad user  
 #============================ 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  
 [data]  
      comment = Data Folder  
      path = /data  
      guest ok = yes  
      browseable = yes  
      create mask = 0777  
      directory mask = 0777  
      writable = yes  
      force create mode = 777  
      force directory mode = 777  
      force security mode = 777  
      force directory security mode = 777  


This Samba configuration works in an Ubuntu 14.04. VirtualBox guest OS perfectly. But no matter what I did, this configuration did not work in CentOS. I always got a "Permission denied" error when I tried to access the Samba share from the Windows host using \\centos-guest\data\

Well it turned out, that the problem was a running firewall AND SELinux (Security-Enhanced Linux). To disable both do the following steps in CentOS:

  1. systemctl stop firewalld
  2. systemctl disalbe firewalld
  3. vi /etc/selinux/config
 # This file controls the state of SELinux on the system.  
 # SELINUX= can take one of these three values:  
 #   enforcing - SELinux security policy is enforced.  
 #   permissive - SELinux prints warnings instead of enforcing.  
 #   disabled - No SELinux policy is loaded.  
 SELINUX=disabled  
 # change  
 # SELINUXTYPE= can take one of these two values:  
 #   targeted - Targeted processes are protected,  
 #   minimum - Modification of targeted policy. Only selected processes are protected.  
 #   mls - Multi Level Security protection.  
 SELINUXTYPE=targeted  


After this, reboot the guest OS and you can access the samba shares of your CentOS guest on your Windows host.

But be warned, you disabled the firewall on your Linux guest OS!

If this is not what you want, you should find an alternative approach.

The DevOps Zone is brought to you in partnership with Sonatype Nexus.  See how the Nexus platform infuses precise open source component intelligence into the DevOps pipeline early, everywhere, and at scale. Read how in this ebook

Topics:
samba ,linux ,devops ,centos ,windows

Published at DZone with permission of Ralf Quebbemann, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}