chrisspeck.com

Chris' random ramblings

Connecting to a remote host through a Ubuntu VM and sharing that back to your Windows Host

The VM in this walkthrough is Ubuntu 11.10 32bit (“VM”). It is running on my desktop, the physical machine (“PM”) running which runs Windows 7 32 bit as the Host Operting System (“Host OS”).

Things will be a lot easier for you if your username on your VM (“vmuser”), Host OS (“huser”) and remote host (“rmuser”) are the same.

Part 1: Generate RSA keys on your VM, and install them on the remote host

Follow steps 3 and 4 from the Ubuntu community help page, on your VM:

mkdir ~/.ssh
chmod 700 ~/.ssh
ssh-keygen -t rsa
ssh-copy-id rmuser@remotemachine

Try sshing from the VM to the remote host. If it does not ask you for a password, then key-generation and installation worked. If not, then you must fix this before continuing.

Part 2: Preparing your VM and setting up an entry in /etc/fstab

Install:

  • *samba file server
  • *sshfs
  • *[optionally] Install webmin (will make checking user group, and creating/checking home share a lot easier).
  • *[optionally] Install the ssh meta-package so that you can ssh between your PM and VM.

Create a folder in home called remotehome.

Create a /etc/fuse.conf and add ‘user_allow_other’ to it:

sudo vim /etc/fuse.conf
user_allow_other
:wq

Check that your VM user is a member of the fuse group.

Add the following line to /etc/fstab:

sshfs#rmuser@remotemachine:/home/rmuser /home/vmuser/remotehome fuse _netdev,noauto,user,idmap=user,suid,workaround=rename,allow_other 0 0

In a terminal on the VM, type in mount ~/remotehome to test.

Part 3: Editing your VM’s crontab.

We could have used the ‘auto’ directive in fstab to mount the remote path, however I never got this to run properly within a VirtualBox VM.

An easy work-around is to edit your crontab like this:-

crontab -e

Then add the following line to the bottom of the file:

@reboot /bin/mount /home/vmuser/remotehome

Save your crontab and reboot your VM to check that this is all working. Check that you can open and create files, and make folders etc.

Part 4: (a) Creating a Samba user and (b) sharing your vmuser home folder

4(a) Creating a Samba User.

Open a terminal on the VM and type the following:

sudo smbpasswd -a huser

If your huser != vmuser, then you are in for a World of Pain (TM) and need to carry out these additional steps:

sudo vim /etc/samba/smbusers

Add the following line:

vmuser="huser"

If your huser is part of an Active Directory domain, you need to add that too, i.e.

vmuser="huser" "ADDOMAIN\huser"

4(b) Sharing your vmuser home folder.

You need to either use Webmin to create/turn on home shares (make sure it is writable to authenticated users) or do the following in a terminal on your VM:

sudo bash
cd /etc/samba
cp smb.conf smb.conf.bak
mv smb.conf smb.conf.master
vim smb.conf.master

If you had to edit the file smbusers, then add the following line to the [Global] section:

username map = /etc/samba/smbusers

Find, and uncomment the following lines:

;[homes]
;   comment = Home Directories
;   browseable = no
;   read only = yes

Change browseable to yes and read only to no.

Add the line writeable = yes for good measure.

Save your file, quit vim and then do the following:

testparm -s smb.conf.master > smb.conf
service smbd restart
exit

Part 5: Setting your VM to launch on start-up

In your Host OS, click on the Start button, click on All Programs, find and right click on Startup and choose “Open”.

Right click anywhere within the new Explorer window, and choose New –> Shortcut.

Enter the following for location of item:

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" startvm NAMEOFYOURVM

e.g.

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" startvm Ubuntu32

Click Next, call the name something sensible, other then VBoxManage.exe, and click Finish.

Part 6: Give your VM a second NIC, a static IP and expose it to your Host OS

Shut down your VM, open Oracle VM VirtualBox Manager, click on your VM, and click “Settings”.

Click on the Network group, then on the Adapter 2 tab, and enable the Network Adapter. Change “Attached to:” to Host-only Adapter, note the adapter name and then click ok.

Still in VirtualBox Manager, click on File and then Preferences, click on the Network group, click on the adapter named in the previous step and click on edit. Give the adapter a fixed ip of 192.168.56.1 and network mask of 255.255.255.0. The IP address 192.168.56.1 is the IP on which your VM will communicate to your Host OS.

Fire up your VM. Open a terminal and open up your interfaces file with:

sudo sudo vim /etc/network/interfaces

Make sure your interfaces file looks exactly like this:

auto lo eth1
iface lo inet loopback

iface eth1 inet static
address 192.168.56.10
netmask 255.255.255.0

Save and close the file and restart the VM’s networking service with:

sudo /etc/init.d/networking restart

On your Host OS, edit the file C:\Windows\System32\drivers\etc\hosts and add the following line:

192.168.56.10       ubuntusvr

At this point you should be able to:

  • ping your VM from your Host OS with ping 192.168.56.10 or ping ubuntusvr from the command prompt
  • ssh into your VM from your Host OS to 192.168.56.10 or ubuntusvr
  • browse shares on your VM by opening Explorer and going to \\192.168.56.10\huser or \\ubuntusvr\huser
  • if apache, webmin, psql, mysql or any other sort of server is installed on your VM, access it through 192.168.56.10 or ubuntusvr

Part 7: Connecting network drive

In the Host OS, open Windows Explorer, click Tools –> Map Network Drive. Choose any drive and set the folder to \\192.168.56.10\huser OR \\ubuntusvr\huser, make sure ‘Reconnect at logon’ is checked and click on Finished.

References:
Ubuntu: SSHOpenSSHKeys
How-To Geek: Create a Samba User on Ubuntu

posted by specky in IT and have No Comments

Batch application of filters in Gimp to make many old photos

I have bunch of files to which I want to apply the “Old Photos” GIMP filter.

For the uninitiated, Old Photos turns this:

into this:


This is a very simple script which will apply the Old Photos filter to every file matching the pattern you supply when you run GIMP. It has no “undo” function and it will save over the input files so be sure to make backups of the originals and only run this script on copies.

To call it you run:

gimp-2.6 -i -b "(many-old-photos \"*.jpg\")" -b "(gimp-quit 0)"

You can download make-many-old-photos.scm here or click here to view the code.

posted by specky in Downloads,IT and have No Comments

Flash Card Printer (returns!)

I have noticed from my Google Analytics that a few people are landing here in search of my Flash Card Printer.

Well, here it is: Setup_Flash_Card_Printer_v1

It lets you create multiple paired lists, with entries in ‘Language 1′ matched against entries in ‘Language 2′.

When you print these lists, the items from the ‘Language 1′ column will be printed on the odd pages, according to a grid that you specify (from 1×1 to 10×10).

The alternate entries within the ‘Language 2′ column will be printed on the even pages, however their horizontal order will be flipped (so that the correct ‘Language 2′ cards are printed on the proper ‘Language 1′ cards).

It supports UTF8 character encoding and the Windows XP alternative Input Editors, so you should be able to use it to create Flash Cards in any language validly installed on your Windows XP system.

I made it to help me learn Italian (and Visual Basic.Net), however it is quite conceivable that you could use this to create flash cards for any subject that can be represented by text…such as mathematical formula, commerce concepts, legal case names etc etc.

You could also use it to print off your own games.

I had intended to incorporate the ability to share lists with other users, and if I can see that there is support for this idea I may spend some time on implementing that feature.

The license for this is “This is free to use for individual use, however use within a commercial setting for for a public purpose requires a license (see the ‘Contact’ page for details).” however I am contemplating changing this.

posted by specky in Downloads,Uncategorized and have No Comments