Linux – Access Samba share from Windows 10 in VirtualBox

linuxnetworkingsambavirtualboxwindows 10

I read a lot of user questions and blogs about this concern, but nothing fixed my issue.

I have a Linux CENTOS host with Windows 10 guest installed in VirtualBox. On Linux, there's a user named "myuser" which shares a directory (777) and is registred to Samba user database. This user has no password restriction. The smb.conf looks like this:

[global]
workgroup = WORKSPACE_SHARE
security = user
map to guest = bad user

[public]
path = /home/myuser/public
public = yes
writeable = yes
comment = smb share
printable = no
guest ok = yes

Windows has a local user with the same name ("myuser", no password set), file and printer sharing enabled, Microsoft Client enabled, workgroup set which matches the Samba workgroup and uses a private network.

In explorer I can see the Linux host which, indeed, contains the shared folder ("public"). But when a try to access this shared folder, an error alert appears: You do not have permissions to access…

On the internet I read things like "Windows 10 uses SMBv3 but Samba doesn't yet support it" and how to turn SMBv3 off – but it didn't help.

Even modification of Local Security Policies on Windows didn't do the trick: https://superuser.com/a/916835/408191

How can I fix this weird issue?

Best Answer

Some Linux distributions have a so called SELinux implementation in its kernel. It stands for "Security-Enhanced Linux" and, beside other things, restricts Samba shares. If you want to create a share folder then it's not not enough to specify convenient access permissions and a definition in samba.conf. You also need to set the correct "Security Context" of the share folder.

Following permission mask and security context should do the trick:

chmod -R 770 yoursharefolder
chcon -R -t samba_share_t yoursharefolder

All conditions that are already known from different wikis must also be adhered:

  • Unix user as owner of the share must be added to Samba user database: smbpasswd -a youruser
  • Your windows machine must have a user with the same name and same password as set in Samba database
  • Your samba.conf may look like this:

samba.conf (all upper-case parts must be customized for your concerning specific environment):

[global]
workgroup = SAME_WORKGROUP_AS_CONFIGURED_IN_WINDOWS
server string = Samba Server %v
netbios name = HOST_NAME_OF_YOUR_LINUX_MACHINE_ON_NETWORK
security = user
map to guest = bad user
dns proxy = no

[yourshare]
path = /PATH/TO/YOURSHARE
valid users = YOUR_WINDOWS_USER_NAME
browsable = yes
writeable = yes
guest ok = no
read only = no
directory mask = 0770
create mask = 0770

Edit: Note that changes via chcon aren't permanent. In order to do permanent security context changes use following command:

semanage fcontext -a -t samba_share_t /full/path/to/your/share/folder

...and to make it effective:

restorecon -v /full/path/to/your/share/folder
Related Question