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.
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:
- Open up My Computer
- Go to the Tools menu and then Map Network Drive
- Choose a drive letter to map the network share to
- In Folder, enter: \\HOSTIP\sandbox (replacing HOSTIP)
- Click “Connect using a different user name” and enter:
- username: sandbox
- password: yourpassword
- 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!
July 29, 2008 — 4:20 pm
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?
July 31, 2008 — 12:08 am
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!
August 8, 2008 — 10:27 pm
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
August 24, 2008 — 8:49 pm
Fantastic tutorial, apart from me being an idiot and running the steps from a root terminal(sigh).. brilliant!
September 18, 2008 — 5:52 pm
Thanks for the tutorial. I just upgraded to Ubuntu 8.04 and it worked like a dream.
September 18, 2008 — 7:10 pm
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!
September 18, 2008 — 7:11 pm
could you also write here how to set up a firewall to work correctly?
September 24, 2008 — 3:58 am
Wow. What a great service you’ve provided for the Ubuntu (et al.) community. Thanks so much – it worked like a charm!
September 26, 2008 — 3:17 am
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
October 4, 2008 — 7:15 am
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 !
October 4, 2008 — 7:19 am
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
October 7, 2008 — 8:08 am
Nice Tutorial.
Thanks a lot…
All work fine.
October 10, 2008 — 9:56 pm
Great guide. Thanks a ton for putting this together.
October 19, 2008 — 6:45 am
Hey thanks I did this in reverse with Ubuntu Server as the guest and Vista as the host, worked like a charm
October 23, 2008 — 7:41 pm
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
October 24, 2008 — 2:19 am
thanks alot it worked.
October 28, 2008 — 2:50 pm
very good
it worked at the first attempt
November 3, 2008 — 7:37 am
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!
November 12, 2008 — 11:25 am
Many thanks for your article! This help me configure Debian (etch) the same way…
December 9, 2008 — 8:55 pm
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???
December 22, 2008 — 7:57 am
Thanks.
Your tutorial configured my samba like a breeze.
December 29, 2008 — 12:57 am
Thanks so much! I’m finally sharing files.
February 11, 2009 — 11:32 pm
Thanks, worked perfectly
March 11, 2009 — 10:12 am
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.
March 12, 2009 — 12:41 am
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.
March 31, 2009 — 1:22 am
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)?
April 7, 2009 — 3:09 pm
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.
July 14, 2009 — 8:02 pm
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
February 18, 2010 — 6:36 pm
thank for your post ..really useful…
December 22, 2010 — 6:03 am
Good Step-by-Step Guidelines. Great Heal and Thanks a ton
May 3, 2011 — 11:03 am
thank you. very complete tutorial. I can connect my host and my virtual system operation now
August 28, 2011 — 10:09 am
Thanks man!!
U are a life saver!!
😀
November 3, 2011 — 10:36 am
Great Guide! Was struggling to transfer data from Ubuntu to Windows.
Thanks a lot!
January 27, 2012 — 12:06 am
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.
October 3, 2014 — 8:22 am
Russ,
You’re amazing! Thanks a ton.
Best,