VMware vSphere client over a SSH tunnel

Reaching a virtual host remotely with the vSphere client through a SSH tunnel is not as straight forward as one could hope. However, it is possible with a few simple steps.

How to connect to a remote ESXi server through a SSH tunnel

I will present two examples, one using the Putty GUI and the other with command line arguments for Putty.

A. Putty GUI

  1. Create or open an existing session to a machine located on the ESXi management network.
  2. Go to Connection – SSH – Tunnels and add the following tunnel configurations:

    Replace 10.0.0.254 with the IP of your ESXi host.
  3. Return to the session settings and make sure you save your settings . It is always a pain to realize when pressing Open to early.
  4. Connect to the machine with the newly created session
  5. Due to some issues in the vSphere client we need to add an entry to the Windows hosts file. Open notepad with administrator privileges (needed to make changes to the hosts file) and open the file (without file extension):
    C:\Windows\System32\drivers\etc\hosts
    (hint: copy paste the about line into the Open file dialogue)
  6. Add a line at the end of the file
    127.0.0.1 esxiserver
    Save the file and exit Notepad
  7. Fire the vSphere client and enter esxiserver as “IP address / Name” and your login credentials.

B. Putty command line

  1. Instead of setting up a Putty session with the GUI
    putty.exe -L 443:destIP:443 -L 902:destIP:902 -L 903:destIP:903 user@local_machine
    (all the above on the same line) where destIP is the IP of the ESXi-server, user is your username on the local_machine and local_machine is the machine on the local network. Hit enter to launch the SSH session and log in.
  2. Setup the hosts file as described in step 5-6 in the previous section
  3. Launch the vSphere client and connect as described in step 7 above.

Raw Device Mappings in ESXi 5.1

Raw Device Mapping (RDM) is a a method to pass a physical drive (that is detected by ESXi) to a virtual machine without first creating a Datastore and a virtual hard disk inside it.

Here is how to setup a drive with RDM to a VM:

  1. Enable SSH on the host. Log in to the physical ESXi host. Under Troubleshooting Options select Enable SSH.
  2. Log in to the host with your favorite SSH client
  3. Find out what the disk is called by issuing the command:
    ls -l /vmfs/devices/disks/
    The device is called something like:
    t10.ATA_____SAMSUNG_HD103SJ___________S246JDWS90XXXX______
    Make sure you determine the correct drive to use for the RDM. Entries with the same beginning as above but ending with :1 is a partition. This is not what you want, you want to map the entire drive.
  4. Find your datastore by issuing the command:
    ls -l /vmfs/volumes/

    It should be named something like:
    Datastore1 -> 509159-bd99-…
  5. Go to your Datastore by issuing the command:
    cd /vmfs/volumes/
    Datastore1
    (Type ls and you will see the content of this Datastore)
  6. Here comes the actual mapping. Issue the command:
    vmkfstools -z /vmfs/devices/disks/<name of disk from step 3> <RDM>.vmdk
    Where you replace the <name of disk from step 3> with the actual disk name and <RDM>with what you would like to call the RDM. A concrete example:vmkfstools -z /vmfs/devices/disks/t10.ATA_DISKNAME_ SamsungRDM.vmdk
  7. Log in to the vSphere client
  8. Shutdown the virtual machine that you want to add the RDM to
  9. Open the settings for the virtual machine
  10. Under hardware tab, click Add…
  11. Select Hard Disk and press Next
  12. Select Use an existing virutal disk
  13. Press Browse, go to the datastore we found in step 4 and select theSamsungRDM.vmdk we created in step 6.
  14. Press Next, Next and Finish to finalize the add hardware guide.

The hard drive is now added to the VM. Just start it up and start using the drive.

Note 1: I was trying to be a smart ass by using the path /dev/disks/ instead of /vmfs/devices/disks/ to point out the disk for the vmkfstools and it refused to accept it.

Note 2: SMART monitoring does not work on drives used as RDM.