2tap.com

Sharing files between a Windows guest and Ubuntu host using VMware and Samba

VMware Workstation (and presumably the other enterprise-grade products in the VMware family) come with the handy “shared folders” feature which makes sharing files between a host and a virtual appliance nice and simple. The free products (VMware Player and Server) do not, unfortunately, have this ability and so we must find another way.

This quick guide shows how to use Samba to achieve the same aim. It is aimed at Ubuntu users but (the general concepts at least) should work on any modern Linux distribution. It is also written with a Windows XP guest in mind but a similar process should work in Windows Vista, Windows 2000 and other operating systems.

The goal is to set up a network share which both operating systems can transparently read and write to.

For reference, I am using Ubuntu 7.04 (Feisty).

Which VMware?

I’ll presume you have VMWare already installed with a Windows XP guest virtual appliance already set up. This guide is aimed at users of VMware Player and Server editions (I am using VMware Player).

VMware Player is a simple:

sudo apt-get install vmware-player

away. For the Server edition, you’ll probably want to consult the wiki.

Install Samba

If you don’t already have Samba installed, now would be a good time to do it:

sudo apt-get install samba

In order to keeps things clean and easy to manage, we’ll set up a new user account to own the share. This account name will be used when connecting to the share from within Windows. For the purposes of illustration, I will be creating a share called sandbox with the username and group also being sandbox.

Create the new group and user account with no login privileges:

sudo groupadd sandbox
sudo useradd --gid sandbox --shell /bin/false sandbox

To avoid creating a redundant home directory, you can add:

--home /nonexistent

to the end of the previous command.

Now you need to add a matching Samba account. You’ll be prompted to set a password – make note of this as this is what you will use to connect to the share from within Windows.

sudo smbpasswd -a sandbox

Next you’ll need to create a directory to be used as the share (assuming you don’t already have one). Create a directory, setting the username to your usual login and group to sandbox. Then chmod the directory 775 (assuming you wish both yourself and the virtual appliance to have read/write access). Here is what I entered:

cd $HOME
mkdir sandbox
sudo chown russ:sandbox sandbox
sudo chmod 775 sandbox

When you write to the share from within Ubuntu, new files will be created with the default permissions 644 with the username and group being your own user account. When your Windows client connects to the share, it will access it as if it were the local system user sandbox and so the group permissions will apply and you won’t be able to write to any files created from within Ubuntu.

To get around this problem, we can set the groupid bit for the sandbox directory which means all new files created will inherit the permissions of the parent and so the sandbox user from within Windows will be able to make read and write changes as desired, you can download them as pdf with sodapdf.

sudo chmod g+s sandbox

If you don’t understand the above, don’t worry, just chmod the directory with the command above and all should be well.

Setting up the Samba share

Now all that’s left to do is to tell Samba about our share. Open up /etc/samba/smb.conf in your favourite text editor.

sudo gedit /etc/samba/smb.conf

Firstly, we need to set the security mechanism to user. Look for the line:

security = user

and make sure it is uncommented (remove the preceding semicolon if there is one).

Now, scroll down to the Share Definitions section and add the following:

[sandbox]
path = /home/russ/sandbox
valid users = sandbox
read only = No
create mask = 0777
directory mask = 0777

Be sure to set the correct path to your share. Save the file and restart the Samba daemon:

sudo /etc/init.d/samba restart

That should be it. You should now be able to connect to your share from within the Windows guest. At this point you need to know what IP address to connect to from within Windows. This depends on what networking mode you are using for your virtual appliance.

Bridged Networking

In this mode, your guest OS has its own IP address and so the address it needs to connect to is your usual host machine’s address. In this case your address is probably the top line from the output of this command:

ifconfig | grep "inet addr:"

NAT networking

In this mode, your guest OS shares your host’s address (in terms of other machines on the LAN) and communicates with the host via a private network. In this case, the IP address you need to connect to is most likely the bottom one from the output of this command:

ifconfig | grep "inet addr:"

Connecting to the share from within Windows

If you are unsure as to your host’s IP address, try and ping it first from within the Windows guest to confirm you have the right one.

Windows Map Networking Drive dialog

Having worked out what IP address to connect to, you should now be able to connect to your share from within Windows.

The easiest way to do this is:

  1. Open up My Computer
  2. Go to the Tools menu and then Map Network Drive
  3. Choose a drive letter to map the network share to
  4. In Folder, enter: \\HOSTIP\sandbox (replacing HOSTIP)
  5. Click “Connect using a different user name” and enter:
    • username: sandbox
    • password: yourpassword
  6. Click OK and then the Finish button to connect

Hopefully, congratulations are in order. If not, be sure to make sure that any firewalls you have running (host or guest) have the correct rules set to allow communication between the two systems.

A note on security

At this point, assuming you have a successful connection, it is worth noting that any other machine on your local network (and potentially the internet if you are not behind a NAT or firewall) can connect to your share (assuming they have the correct credentials).

If you are only using Samba for sharing with VMware (as I am), you may wish to restrict access to VMware only. This is quite easy to do since VMware creates virtual network interfaces for communication between hosts and guests. This means we can set Samba up to ignore any communications that do not originate from these interfaces.

To do this, open up your Samba configuration file again:

sudo gedit /etc/samba/smb.conf

Make sure you have a:

bind interfaces only = true

line and that it is uncommented (remove any preceding semicolons). Just above this should be an interfaces line (most likely commented out). Add the following just below this:

interfaces = vmnet0 vmnet1 vmnet8

These are the virtual interfaces VMware uses for each type of virtual networking: bridged, host only and NAT respectively.

After making the changes, you will need to restart Samba again:

sudo /etc/init.d/samba restart

and possibly shutdown your VMware session and restart the VMware service:

VMware Player:

sudo /etc/init.d/vmware-player restart

VMware Server:

sudo /etc/init.d/vmware restart

Finished

You should now have a Samba share configured which is only accessible from your VMware guest appliances. Good luck!

Categories: Linux, Ubuntu

Parklife » « Tap Trap 1.1 – New features

50 Comments

  1. thanks it worked

  2. Thanks for the guide. Got everything up and running smoothly!

  3. Connecting to SAMBA from the windows guest just doesnt seem to work in bridged – any ideas. Worked first time in NAT.

  4. Thank you! Just worked!

  5. Thanks a lot for this tutorial. I’ve been trying to get samba+vmware to work for days. Now it’s up and running.

  6. i followed all the steps and at last when trying to connect with map network drive from windows, it says that the network location cannot be reached… :( and i am pretty sure that i have done everything correctly

  7. i changed vmware to use NAT connection and it worked like a charm :) thanks… still, not understanding why the bridged connection didn’t work.

  8. Thanks for posting this, it worked perfectly on my ubuntu feisty x64 install.

  9. it workes for me

    exept for the line
    interfaces = vmnet0 vmnet1 vmnet8
    for some reason it get blocked

    maybe it would be nice to publish your .vmx fille

  10. Thanks a lot, it works very well. had the problem where the network bridge did not connect but switching to NAT worked great.

  11. Thanks. This works. I’ve got a debian linux as VM (running through VMplayer) on my windows XP desktop & I was able to successfully share a folder between the VM and my desktop.

  12. Interesting Arun – I didn’t consider the possibility of doing this in reverse!

    Glad you were successful.

  13. If any of you see your files/folders in the winxp share but cannot access the files, don’t forget to check the file/folder permissions of the items you transferred into the “sandbox” folder.

  14. thank you for the well written and understandable tutorial, it now works

  15. Hi !

    does not work with bridged network.

    Any ideas ?

    thanks
    karl

  16. I have Ubuntu as the host, and Win XP as the guest. I can see an Ubuntu shared folder from Win XP. I can see a Win XP shared folder from another computer. But when I am on my host computer and I try to explored shared folders on the Windows XP virtual machine, Ubuntu shows me the Ubuntu shares instead! Bridged connection.

  17. Oh, but if I use the IP address of the virtual machine as the server name, it works.

  18. Same as Mike, everything worked but the interfaces option.

    If I execute ifconfig while VMware player is running, I do not have any vmnet0 device. I have tried NAT and bridged but there were no changes.

    If I do not use ‘interfaces’, everything works, but I would like to block connections from outside.

    Any idea? Thanx!

  19. Problem solved! I was using a wrong IP address. Works like a charm!!

  20. Thanks,

    It worked perfectly for me too!

  21. Thanks for the tutorial.

    In case I use NAT everything works perfectly (including bind interfaces only = true), but no success using BRIDGED so far.

  22. Thank you it works fine. I still have a question… Your “trick” suppose that you are connected to the internet. Is it possible to use this trick without being connected to the internet?

    Thanks again

  23. A way (workaround) for using bridged connection and having the samba share to work is to add a second ethernet adapter of host-only type to the virtual machine and use this one to map the network driver.

    Running “ipconfig /all” in the guest system will show two IPs. The first one related to your bridged connection and the second one for your host-only connection, in my system the latter is 192.168.150.128. Hence when I map my network drive I use:
    \\192.168.150.1\sandbox

  24. Thank you for your How To. It solved a lot of problems.
    a couple of comments to make thing more clear. This command didn’t work:
    sudo chown russ:sandbox sandbox
    because “russ” is the author’s name (not readers one). So according to the explanation in the HowTo it should be:
    sudo chown sandbox:sandbox sandbox
    that is also pretty puzzling. Generally it should look like:
    sudo chown username:group foldername
    It would be better to apply different names to group, user and folder, just for the purpose of the tutorial.

    Another issue was with the connection. Maybe I am wrong, but we can’t use the existing NAT, which is used by VMWare internally. The connection happened after I had added the second BRIDGET network card to virtual Windows.

    But this How To was the only which worked for me, thank you very much!

  25. Everything worked for me (on Ubuntu Feisty) but for the binding to the interfaces. I noticed that when I change the following line:

    interfaces = vmnet0 vmnet1 vmnet8

    to:

    interfaces = vmnet0, vmnet1, vmnet8

    it ALL worked!

    Thank you very much for the tutorial!

  26. Thanks a lot for this tutorials. Initially only NAT worked for me because I messed my samba config but after following this guide and vmware docs bridge mode works as well.
    I’m using Ubuntu 64bit host and vista ultimate 32bit as guest. I can see vista vm from ubuntu and vice versa.

    Thanks again.

  27. Thank you thank you ! I’m new to linux and the piece I was missing was the permissions. I didn’t have them quite right but you showed what permissions were required which is just what I needed

  28. Fantastic, straightforward “how to”, worked perfectly thank you :)

  29. Thank you very much for this great comprehensive article. You saved me a lot of time and effort.

    thanks,

    R
    keep spreading the knowledge

  30. Thaks. good Job. you saved my day

  31. Man…
    You really kick ass!!!

    This post was wonderful…
    I have made through the steps smoothly… An in addiction I’ve learned how to share folders in my windows network!

    Thank you very much!

    (Votes up for StumbleUpon)

  32. Great tutorial !!! Everything works like a charm

  33. Hi,

    I am having trouble getting Windows (Vista Home Premium) to see my Linux machine. I have followed the instructions above but I cannot determine the correct IP address to connect from within Windows (I tried 192.168.1.3).

    I also did an ipconfig /all command from Vista, but it did not return a device with an IP of 192.168.1.3.

    Here is the IP info from Linux. Can anyone help?

    Thanks!
    -Josh

    josh@Gateway:~$ sudo gedit /etc/samba/smb.conf
    Fontconfig error: “~/.fonts.conf”, line 1: XML declaration not well-formed
    josh@Gateway:~$ sudo /etc/init.d/samba restart
    * Stopping Samba daemons… [ OK ]
    * Starting Samba daemons [ OK ]
    josh@Gateway:~$ ipconfig -a
    bash: ipconfig: command not found
    josh@Gateway:~$ /sbin/ifconfig
    eth0 Link encap:Ethernet HWaddr 00:0C:F1:99:0F:16
    inet addr:192.168.1.3 Bcast:192.168.1.255 Mask:255.255.255.0
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    RX packets:949866 errors:0 dropped:0 overruns:0 frame:0
    TX packets:706138 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:926253488 (883.3 MB) TX bytes:86261274 (82.2 MB)

    lo Link encap:Local Loopback
    inet addr:127.0.0.1 Mask:255.0.0.0
    UP LOOPBACK RUNNING MTU:16436 Metric:1
    RX packets:4696 errors:0 dropped:0 overruns:0 frame:0
    TX packets:4696 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:0
    RX bytes:711559 (694.8 KB) TX bytes:711559 (694.8 KB)

    josh@Gateway:~$

  34. Thank you!!! It worked perfectly 😉

  35. It really work !!! My machine is Ubuntu Host and windows xp Sp2 Guest Os.

    Thanks a lot for this useful guide.
    salu2

  36. Just too good!

  37. Works, only for NAT, I have not been able to make it work on Bridged, however, this post was simply amazing and wonderful!!! Thanks for sharing your knowledge with us!!!

  38. Hi , just wanted to say great tutorial, relatively new to Linux and this worked like a dream. Like some previous posts am having issues when trying to lock down share to vmnet connections only IE The final step in your instructions but can probably live with that till I figure out why.

    Cheers

    Jeff

  39. A really good tutorial.
    I was very disappointed that the Workstation solution
    was not available and couldnot find the correct route
    myself.
    Now it works!
    Thank you very much!

  40. I’ve just tried under ubuntu 7.10 and XP on laptop, excellent how-to, works fine. Thank You.
    Greetings from Polland.

  41. Hi Russ,

    Thank you very much for this clearly written tutorial – works perfectly (Ubuntu on Vista).

    Great work,

    Rgards,

    Mike.

  42. Great explanations!!!

    many thanks,

    gennaro

  43. I have been trying to do this for ages. Finally some instructions that lead step by step. Thanks.
    kathy

  44. Great post.

    On my system (RHEL) using NAT in order to find the correct IP address I had to go to my XP Guest and open a CLI (cmd.exe) then do

    ipconfig

    The gateway address is the one I needed.

    HTH

  45. it worked ! wow! thanx a lot!
    id been struggling with this file sharing issue for like a month … very frustrating

  46. Hi Russ!

    Thanks a lot for the tutorial. It worked for me – NAT, not bridged! (Win XP on Ubuntu Hardy 64 bit)

    Best wishes,

    Dan

  47. Thanks!!! Things are working!!!
    But, I forget my sandbox’s password. Actually, I think I typed in correctly but got rejected, I tried to switch user to sandbox in my host, the password is really wrong. Please, how to reset it?

  48. Russ, Thanks a million for posting this step by step guide for novices like me. I had installed VMWare Workstation and simply could not get their VMWare Tools to install to allow me to transfer files back&forth between Windows Vista Host and Ubuntu Linux running as a virtual machine.

    I followed your instructions to the T and I now have a shared (mapped) drive on Windows where I can easily deposti files that Linux can see and vice-versa. Simply amazing..

    Thanks again. -Ashok

  49. great work, thanks a lot!
    Like most of people here, struggling with this for already a long time and now found an easy solution.
    thanx mate!

  50. Excellent guide… got me up and running very quickly. Glad to find the link to this page in the Ubuntu Forum.

Leave a Reply

Your email address will not be published.

*

Copyright © 2024 2tap.com

Theme by Anders NorenUp ↑