People like to try out things. Most things tend to be risky and dangerous, and normally mess up your working system. So that’s why we use virtualization technologies.
Let’s imagine you are a web developer. You normally use Windows or Mac OS X and you do not have any intension to change that. But you need a development environment to test things, and that’s where you have a choice. You can grab a native web-server for your system, which means partial incompatibility to your production environment, system instability and conflicts to other software in most cases. But you can also install a clean web-server-optimized OS (Debian?) in a virtual machine (VMWare, Parallels?). This will guarantee full portability to your production server and overall stability. The only real problem is the workflow – editing files on your local file system and then pushing them onto the VM is really annoying. Not each system supports Shared Folders, especially Unix-like ones. But there is a way:
We are going to setup Samba to share folders. Our intension is to keep the configuration work for Samba as minimal as possible, since there is no need in a full-fledged CIFS domain controller.
- Install Samba. For Debian/Ubuntu:
apt-get install samba. If you are being asked for the name of your workgroup, just enter it in uppercase
- Locate the configuration file smb.conf. Usually in /etc/samba/smb.conf or /usr/local/samba/smb.conf
- Open smb.conf and uncomment the line containing security = user. It enables a very simple authentication mode, where Samba users are mapped one-to-one to the local system users, and CIFS file permissions are identical to those of the local file system
- Comment the lines containing passdb backend = tdbsam and obey pam restrictions = yes
- Check if the name of the workgroup is correct, if not – change it to the right one
- Go to the [homes]-Section of the file and set
writable = yes
Now we’re done with the basic configuration. But we need a user. The most convenient way is to add one with the same username and the same password as the one that you are using on your host OS. Let’s say, bob is your username.
- First, we need to add a system user:
useradd -m bob
-m creates a home directory for the user, which will be your Samba-share.
- Then, we add a Samba user with the same name and password:
smbpasswd -a bob
- Restart Samba to apply changes we made to its configs:
- Finally, mount your share. Let’s say, the IP of your VM is 18.104.22.168.
For Windows systems, you just have to open \\22.214.171.124 in the Windows Explorer and then authenticate. The shared folder bob is your home directory on the VM.
If you’re cool and use Mac OS X, you open the Finder, press ⌘K (or Menu: Go->Connect to Server) and enter smb://126.96.36.199. The rest is self-explanatory.
If you don’t need files which are outside of your home directory – congratulations, we’re done by now! But if you do need access to, for instance, /var/www/, there is a way:
- Gain read/write-access to the folder. Possibly like this:
chown -R root:bob /var/www
chmod -R g+x /var/www
- Create a share for the folder:
path = /var/www
writable = yes
valid users = bob
- Reload Samba configuration with /etc/init.d/samba reload
- Mount the new share – its name is now docroot
Feel free to mail me if you experience problems or have a better solution. Check this link for an excellent book on Samba.