Accessing VirtualBox Guests from Host using SSH, WinSCP and Tunnelling
Accessing VirtualBox Guests from Host using SSH, WinSCP and Tunnelling
Accessing Virtual Machine using SSH via a Terminal
Open up a terminal in your host system. This is usually the application called Terminal in Linux or OSX; start PuTTY if in Windows.
Now connect using the SSH client to localhost and port 2201 (or whichever you choose in Port Forwarding). On the command line that is performed using the -p option. The -l option may also be used to specific the username for the guest login:
sgordon@lime:~$ ssh -p 2201 -l network localhost
network@localhost's password:
Welcome to Ubuntu 12.04.1 LTS (GNU/Linux 3.2.0-23-virtual i686)
* Documentation: https://help.ubuntu.com/
System information as of Fri Jun 21 14:23:35 ICT 2013
System load: 0.16 Processes: 76
Usage of /: 14.4% of 7.47GB Users logged in: 1
Memory usage: 33% IP address for eth0: 10.0.2.15
Swap usage: 0% IP address for eth1: 192.168.1.10
Graph this data and manage this system at https://landscape.canonical.com/
Last login: Fri Jun 21 13:01:01 2013 from 10.0.2.2
network@client:~$
In Windows using PuTTY when connecting make sure you set the Host Name to localhost and change the Port to 2201. It looks similar to this:
Once connected you are now accessing the virtual guest.
Exploring and Sharing Files on the Virtual Machine (Linux only)
In Linux and OSX you can use scp in the Terminal to copies files to/from the guest. PuTTY in Windows also supports command line based file copying with pscp. Another alternative is to use WinSCP to copy files in Windows. However it would be nicer to be able to view and copy files using the standard file explorer on the host. The following describes how to do this in Ubuntu Linux using the standard file explorer called Nautilus (it should be similar with other Linux distributions and file explorers). The alternative techniques - scp, pscp and WinSCP - are described later.
In Ubuntu Linux (on the host computer) you can also use Nautilus, the default file explorer, to connect to the SSH server on the virtual machine.
From the File menu, select Connect to server .... Change the Type to SSH and then set the following:
- Server: localhost
- Port: 2201
- Folder: /home/network
- Username: network
- Password: network (or whatever you chose)
Once connected you can manage files on the virtual machine, including copy-and-paste to/from your host machine using the GUI provided by Nautilus.
Copying Files Between Host and Guest using Command Line (Linux, OSX)
If you can't or don't want to use the file explorer in your host to copy files, then you can use the command line. On most Linux/Unix systems (including OSX), scp can be used in a terminal on the host. The general format is to specified the source and destination, where one of them (depending which direction you are copying) includes the remote address.
To copy a file example.txt in your current directory on the host to the guest use the following. Note that you indicate the port using the -P option and the guest username is given before the @ character.
$ scp -P 2201 example.txt network@localhost:/home/network/
network@localhost's password:
example.txt 100% 6 0.0KB/s 00:00
And to copy a file index.html in the users tmp diretory on the guest to the host:
$ scp -P 2201 network@localhost:/home/network/tmp/index.html .
network@localhost's password:
index.html 100% 177 0.2KB/s 00:00
Copying Files Between Host and Guest using Command Line (Windows: PuTTY)
In Windows, you can use pscp.exe (which is included with PuTTY) in a similar manner to scp (see above). If you expect to use it in a regular basis, then set the path. Instructions for setting the path in Windows, and for using pscp.exe are given in the PuTTY manual.
See below if you'd prefer to use a GUI in Windows, instead of the command line.
Copying Files Between Host and Guest using WinSCP (Windows only)
WinSCP is a free, open source Windows application that provides a GUI to transfer files to/from a SSH server, i.e. between host and guest. Download, install and the connect to the server as below:
Using the Host Web Browser to Access a Guest Web Server
The default setup of the virtual network uses only terminal access on the guests. There is no GUI or window manager on the guests. That makes using a web browser on a guest difficult: you are restricted to a terminal based text browser like Lynx. If you want to run a full web browser, like Firefox, on a guest then a full desktop environment needs to be installed on that guest. This takes up a lot of disk space and may also require more RAM for the guest. An alternative is to use the web browser on your host to access the web servers on your guests. It involves SOCKS tunnelling. Lets go straight into how to do it, with an explanation of how it works later.
On your host, connect to the guest using SSH and a special tunnelling option. With ssh on the command line in Linux/OSX, this is performed using the -N and -D options:
$ ssh -ND 3333 -p 2201 -l network localhost
network@localhost's password:
After entering the password there will be no visual response - leave this terminal open.
Now in your web browser preferences/settings, you need to enable proxying specifically using SOCKS. In Ubuntu Firefox, go to Edit menu and select Preferences. From the Advanced icon select the Network tab and press the Settings button. This lets you to set a proxy. Choose Manual proxy configuration and set the SOCKS Host to localhost and the Port to 3333 (or whatever you selected when starting ssh with the -ND option). It should look similar to the following:
Now your host web browser will connect to the SSH client on the host, which in turn is connected to the SSH server on the guest. All of your host web browser traffic will go via the guest. In your web browser address bar, type in the IP address of the guest, e.g. 192.168.1.1. You should see the web page offered by that guests web server.
Comments
Post a Comment