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

35 Comments

  1. Russ, Thank you very much for your well thought out and written guide…

    I am been puzzling over this for a while, and was suprised to find a clearly laid out “how to”.

    It took me more time to “cut and paste” then it did to implement a sandbox. Furthermore your example made it a little more cleared on how to effectively use samba.

    Got any more tips and technques?

  2. Thanks for the guide! I am new to ubuntu and followed the how-to to install an XP host on my Ubuntu. I had troubles connecting to my Ubuntu shares until I found your guide!

  3. Thank you for this tutorial, everything ran perfectly. I used it to configure sharing between a Windows host and a Linux guest, there was only one step that didn’t quite work at first. Instead of using the “Map Network drive” tool in Windows, I had to open the type
    net use (drive letter) \\(ip)\folder

  4. Fantastic tutorial, apart from me being an idiot and running the steps from a root terminal(sigh).. brilliant!

  5. Thanks for the tutorial. I just upgraded to Ubuntu 8.04 and it worked like a dream.

  6. if you have winbinds? (i don’t remember exactly), well wine depends on that, so wine installed, things just don’t work on ubuntu 8.04

    after removing them, everything is fine.

    thanks for the tut!

  7. could you also write here how to set up a firewall to work correctly?

  8. Wow. What a great service you’ve provided for the Ubuntu (et al.) community. Thanks so much – it worked like a charm!

  9. A couple of things you might want to consider doing differently:
    You don’t need a separate user, so

    username = my_username
    create mask = 644
    directory mask = 755
    force user = my_username
    force group = my_group

    Then in Windows map the share; select ‘connect using a different…’ and enter your username–Windows likes to capitalize your username which may lead to problems.

    That way you don’t have to worry about being able to write another user’s files, and you prevent windows from misbehaving in re file ownership (although that may not be necessary).

    Cheers

  10. Hey big thank you for this post man . . been up 3 nights straight trying to get this work on my Ubuntu Hardy 8.04.1 and finally i am successful tonight (1am in the morn)
    keep up the good work looking forward to learn lots more from your posts and blogs :)

    thnx again !

  11. For the record i’m using the free version of
    Vmware Server 1.0.6 build-91891 and
    Ubuntu Hardy 8.04.1 of course :)

  12. Nice Tutorial.
    Thanks a lot…
    All work fine.

  13. Great guide. Thanks a ton for putting this together.

  14. Hey thanks I did this in reverse with Ubuntu Server as the guest and Vista as the host, worked like a charm

  15. i am using vmware…and in that bridged….my interface is eth0 in main os…my net is connecting in guest…how can i make net to work in guest

  16. thanks alot it worked.

  17. very good

    it worked at the first attempt

  18. I’m sorry but I am very new to Ubuntu. I have followed all instructions a few times and I can’t connect in Windows. I’m not sure if I have the correct Host IP address. I have tried all that I can find. I am using NAT and I would REALLY appreciate any help I can get.

    Thanks!

  19. Many thanks for your article! This help me configure Debian (etch) the same way…

  20. hi, thanks for this straight forward article, but I can’t figured it out!
    in opensuse 11.0

    sudo /etc/init.d/samba restart
    is
    sudo /etc/init.d/smb restart

    valid users = username
    seems not working

    u can use
    guest ok = yes
    guest account = username

    but it’s not safe and password protected

    what can I do???

  21. Thanks.
    Your tutorial configured my samba like a breeze.

  22. Thanks so much! I’m finally sharing files.

  23. Thanks, worked perfectly

  24. courty@ubuntu:~$ sudo gedit /etc/samba/smb.conf
    [sudo] password for courty:

    ** (gedit:5986): WARNING **: Could not write gedit state file: Failed to create file ‘/root/.gnome2/gedit-2.QKNRQU’: No such file or directory

    I/O error : No such file or directory
    I/O error : No such file or directory
    courty@ubuntu:~$
    courty@ubuntu:~$ sudo gedit /etc/samba/smb.conf

    I tried to find the file mention in samba but with no luck. I do indeed have gnome and I followed the tutorial perfectly. Everything worked wonderfully up to this point.

  25. First, thanks. Thanks a lot. Thank You. Your instructions are well written, clear, thorough and concise. I am not experienced or naturally gifted on a computer. But by shear effort I got to the point of having winxp working within Ubuntu 8.1 on an ibm t23. I do this so I can stay with Ubuntu, but I want to use a windows-only music player. I like Ubuntu very much and the people like you who help folks like me, but I like the music player also. I discovered I could not get file sharing on the virtual winxp. I bumbled and stumbled. You explanation worked for me. I don’t have much comphrehension of what I’ve done but I can now share with a folder of the Ubuntu desktop. On Ubuntu I access my main music file accessed through a network that accesses an external drive on a windows xp desktop.

    Question: can my virtual win xp inside Ubuntu access the external drive?? If so could I humbly ask how? It is a large file and I do not want to load my laptop drive down.

  26. Hi, your tutorial used to work for me, but now, with vmplayer 2.5.0, ubuntu 8.04 (server), the windows xp guest keeps telling me this:
    “The mapped network drive could not be created because the following error has ocured:
    The specified server cannot perform the requested operation.”

    What can I do (I’ve also tried to change from NAT to Bridge, but it didn’t work too)?

  27. You are the man!

    I have heard it said that, “Nothing in Linux is easy.” and even though I got a good book and had enough time on my hands, I fumbled around for a day with vsftp and then decide to try Samba. Well, as usual, Linux wouldnt play nice (always that one little thing…). A search on the web and your little tutorial really helped out. With just a few changes it worked just stellar on Ubuntu 8.1 and a Winders XP pro box. I have 2 network cards in a dedicated Linux file server, each card goes to an XP box and they do their backups on the Linux over 10/100/10000 cards. I get 200mbps transfer speeds with my mongo sized files and all the other features of Linux. So thanks to your tutorial you saved me lots of time and renewed my faith in linux. I am going to print this out and make a few additional notes and keep it as a reference. Thanks again to you and all the others who suggested the minor changes.

  28. Hi – thanks for this amazing tutorial.

    I am not a tech person, but someone installed ubuntu on my pc’s at work and I really love it and the software that they installed for us. Unfortunately some things still don’t work nicely with ubuntu.

    So I installed windows using VM, and then found your tutorial how to share folders.

    Everything seemed to go well, I have no idea really why I do the things I do and what I am supposed to see afterwards, but everything went well, I even pinged from within windows and it worked fine.

    I esablished I have to use NAT.

    So when I went to make the map drive, it keeps on asking me to login.

    But I checked the folders, they appear on the ubuntu pc.

    I rechecked the password and restarted samba as per the instructions.

    So I really don’t know what to do next. I would appreciate any help.

    Thank you
    CazRt

  29. thank for your post ..really useful…

  30. Good Step-by-Step Guidelines. Great Heal and Thanks a ton

  31. thank you. very complete tutorial. I can connect my host and my virtual system operation now

  32. Thanks man!!

    U are a life saver!!

    😀

  33. Great Guide! Was struggling to transfer data from Ubuntu to Windows.
    Thanks a lot!

  34. I’m using VM Workstation 6.5 on a Win 7 Host with Ubuntu 11.11 guest. The VMWare vmtools sharing method breaks with every single kernel update and often has trouble recompiling with the new headers.

    Using a samba share is more robust across kernel updates. The instructions here for a “Ubuntu host / windows guest” work exactly the same for the other way around (win host/ubuntu guest). The only difference is the files are stored on the virtual drive.

  35. Russ,

    You’re amazing! Thanks a ton.

    Best,

Leave a Reply

Your email address will not be published.

*

Copyright © 2024 2tap.com

Theme by Anders NorenUp ↑