How to setup SSH VM Access with Port Forwarding

This guide shows how to connect your laptop to a VM using SSH and port forwarding. The setup is specifically targeted at those running our Charmed Kubeflow or Charmed MLflow with Kubeflow tutorials.

With this setup you will be able to:

  • Access the application UI through your web browser
  • Access the VM through a terminal

These steps assume the following:

  • You are using Ubuntu 22.04 or later.
  • VM access will be secured via a private key stored in ~/.ssh/myKey.pem, and the connection will be to ubuntu@myserver.cloudomain.com. You will need to tweak these details accordingly for your specific use case.

Contents:

Setup

To setup an SSH tunnel with a SOCKS proxy, follow these steps:

Use the ssh command to open an SSH tunnel

For Charmed Kubeflow run this command:

ssh -i ~/.ssh/myKey.pem -D 9999 ubuntu@myserver.cloudomain.com

For Charmed MLflow run this command:

ssh -i ~/.ssh/myKey.pem -L 31380:localhost:31380 -D 9999 ubuntu@myserver.cloudomain.com

Note: for MLflow you’ll see the additional -L 31380:localhost:31380 option. This forwards localhost port 31380 to the remote machine, because we need this to access the MLflow dashboard.

Configure your Ubuntu network settings to use a SOCKS proxy

On your laptop’s network settings:

  1. Open Settings > Network > Network Proxy.
  2. Set the network proxy to ‘Manual’.
  3. Set the SOCKS host to: 127.0.0.1 and port 9999.

Note: Once this is done, all your network traffic will go through the SSH tunnel to the VM. If the SSH tunnel is closed, then you’ll lose internet.

Deactivate

To deactivate this setup, first revert your network settings by disabling the network proxy, then close the SSH tunnel.