Over a million developers have joined DZone.

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

The DevOps zone is brought to you in partnership with Sonatype Nexus. The Nexus suite helps scale your DevOps delivery with continuous component intelligence integrated into development tools, including Eclipse, IntelliJ, Jenkins, Bamboo, SonarQube and more. Schedule a demo today

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:

      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 ==============================  
      comment = Home Directories  
      browseable = no  
      writable = yes  
 ;     valid users = %S  
 ;     valid users = MYDOMAIN\%S  
      comment = All Printers  
      path = /var/spool/samba  
      browseable = no  
      guest ok = no  
      writable = no  
      printable = yes  
      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.  
 # 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.  

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. Use the Nexus Suite to automate your software supply chain and ensure you're using the highest quality open source components at every step of the development lifecycle. Get Nexus today


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

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

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

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

{{ parent.tldr }}

{{ parent.urlSource.name }}