HyperAIHyperAI

Using SSH Tunnel to Access Container Services

:::info Note In addition to using SSH Tunnel, HyperAI also provides a more convenient custom port mapping feature, which can directly expose services inside containers to the public internet.

Selection Guide:

  • SSH Tunnel: Suitable for personal temporary access, no real-name authentication required, only the local machine that establishes the tunnel can access the service
  • Port Mapping: Suitable for scenarios requiring continuous service provision to multiple users, real-name authentication required

The Gradio example in this document can also be implemented using port mapping. For details, see Custom Port Mapping Documentation. :::

SSH Tunnel is a method of forwarding network connections on local or remote computers through an encrypted SSH connection. You can use SSH Tunnel to access services protected by firewalls on remote servers without directly exposing ports to the public internet.

There are two authentication methods for accessing machines via SSH:

  1. Password-based authentication: This method requires users to enter a password for authentication.
  2. Public key-based authentication: This method uses public key encryption technology for authentication. It involves generating a key pair (public key and private key) on the client, and adding the public key to HyperAI. The private key is securely stored on the local machine and used for authentication without requiring a password.

Using Password

HyperAI's SSH service provides password login by default. If you don't want to configure keys, you can follow the Using Password to Access SSH method.

Configuring SSH Key

If you already have an SSH key, you can skip this step. For related information, please refer to Prepare Public Key.

How to Access Ports Using Commands

1. Start an OpenBayes Workspace

Copy the command from the "SSH Access" panel to your computer's terminal to verify if you can successfully access the container. If you see the following content, it means you have successfully accessed the container.

$ ssh root@ssh.openbayes.com -p31552

Last login: Fri May  5 03:47:16 2023 from 10.110.14.192
HyperAI

Directory Description

- /openbayes/home Workspace data storage location, contents in this directory will not be deleted after container stops
- /openbayes/input/input0 - /openbayes/input/input4 are dataset binding locations, these locations have read-only permissions and do not occupy workspace storage capacity, supports binding up to 5 simultaneously

⚠️  Contents in other directories will be automatically deleted after container shutdown! For more information, visit https://hyper.ai/docs/getting-started/concepts

Using Command Line Tools

Use the command bayes gear init to initialize command line tools in the container, more information at https://hyper.ai/docs/cli

(base) root@xushanchuan-fb075g25qn2k-main:/openbayes/home#

2. Start a Gradio Service in the Container

First, open a terminal in the "Workspace" and install Gradio dependencies:

$ pip install gradio --user

Then create an app.py file with the following content:

import gradio as gr


def greet(name):
    return "Hello " + name + "!!"

demo = gr.Interface(fn=greet, inputs="text", outputs="text")
demo.launch()

Finally, run python app.py to start the service. You will see the following output:

$ python app.py

Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.

You can see that the service has started successfully, and the access address is http://127.0.0.1:7860.

3. Access Remote Port via SSH Tunnel

Use the following command to start an SSH tunnel:

$ ssh -N -L localhost:7860:localhost:7860 root@ssh.openbayes.com -p31552

Where root@ssh.openbayes.com -p31552 should match what you see in the "SSH Access" panel.

Then you can access the service locally at http://localhost:7860: