HyperAIHyperAI

Connecting to Running Jupyter Workspace via SSH

Feature Introduction

HyperAI supports accessing running Jupyter-type executions through the SSH protocol. There are two authentication methods for accessing machines via SSH:

  1. Password-based authentication: This method requires users to enter a password for identity verification.
  2. Public key-based authentication: This method uses public key encryption technology for identity verification. It involves generating a key pair (public key and private key) on the client side 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.

:::caution Note Only running "Jupyter Workspaces" can be accessed via SSH protocol. :::

Using Password

After the workspace is successfully created, SSH login information will appear on the page, and a password will be created for the container. This password can be used to complete SSH authentication without any additional steps.

As shown in the image above, click "Copy Password" to obtain it.

Using Public Key

SSH access can be achieved by completing the following steps:

  1. Upload your personal SSH public key to HyperAI
  2. Add SSH access configuration for HyperAI locally
  3. Log in via SSH using the command ssh root@xxx -pxxxx

Preparing the Public Key

Open the command line and enter ssh-keygen -m PEM -t rsa -b 4096 -C "your.email@example.com" (your own email), then press Enter repeatedly to generate a key pair. Windows users are recommended to use PowerShell for this operation.

ssh-keygen -t rsa -b 4096 -C "your.email@example.com"
# Creates a new ssh key, using the provided email as a label
# Generating public/private rsa key pair.
Enter file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]  // Using the default address is recommended
Enter passphrase (empty for no passphrase):   // Press Enter here, or you can set a password. If you set a password, you'll be required to enter it every time you push code using SSH. Since this key is not for military purposes, there's no need to set a password

:::note If you are very familiar with this process, you can follow the regular public key creation procedure. For more information, refer to Generating SSH Public Keys. :::

Upon success, the following information will be displayed:

Your identification has been saved in /Users/you/.ssh/id_rsa.
# Your public key has been saved in /Users/you/.ssh/id_rsa.pub.
# The key fingerprint is:
# 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your.email@example.com

Add Public Key

  1. Open the ~/.ssh directory (on Windows, this is the .ssh directory in the user directory), use an editor to open the id_rsa.pub file (this is the default name for the generated public key; if you used a different name when generating the public key, open the corresponding file), and copy all the content.
  2. Log in to the HyperAI page, click "SSH Settings" -> "Add New Public Key" in the left navigation bar, paste the content into the "Public Key" text box, give this SSH public key a name, and click Add SSH Public Key.

Manage SSH Public Keys with bayes CLI

After installing and logging in to the bayes command-line tool, you can use the bayes ssh subcommand to create or upload public keys to HyperAI:

# Create and upload a new SSH public key
bayes ssh create --name my-device

# Upload an existing public key file
bayes ssh upload ~/.ssh/id_rsa.pub --name my-device

The --name option is used to specify an easily recognizable name for the public key; if not provided, it defaults to the current hostname. Public keys uploaded via CLI will take effect in all workspaces.

Manually Append Public Key

If you cannot use CLI temporarily, you can first log in to the workspace using a password, then execute the following command locally to append the public key to the current workspace:

cat ~/.ssh/id_rsa.pub | ssh -p <port_number> root@ssh.openbayes.com 'mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys'

Replace <port_number> with the port number displayed on the workspace page. This method only takes effect in the currently running workspace and needs to be re-appended after restart.

Log in via Command Line

1. Obtain SSH Login Information

After starting a "Workspace", its page will display SSH login information, as shown below:

Click "Copy Command" to copy the command to the clipboard. The command line is displayed as follows:

ssh root@ssh.openbayes.com -p30360

Where root is the username, ssh.openbayes.com is the server address (which can be an IP or another domain specified by OpenBayes), and 30360 is the port number.

2. Log in to the Running Jupyter Workspace

Paste the above command into the command line or fill in the information into other SSH-compatible clients to log in to the running Jupyter workspace via SSH.

If you haven't uploaded your local public key, you will need to paste the SSH login password at this step.

3. WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED

If the above error is displayed when pasting the ssh login command into the command line, an additional step is needed to resolve this conflict.

Enter the following information in the command line:

ssh-keygen -R [ssh.openbayes.com]:<your workspace port>

Then paste the ssh command copied from "Workspace" again.

Connecting via VS Code SSH

If connecting to a running Jupyter environment remotely via SSH, please first read the VS Code documentation Remote Development using SSH to understand VS Code's support in this area. Also install the corresponding plugin.

1. Install VS Code SSH Plugin

Install the above plugin.

2. Configure SSH Connection in VS Code

Click the bottom left corner to open the remote window.

Select "Connect to Host..." in the command palette and press Enter. Scroll to the bottom of the dropdown menu to see "Add New SSH Host..", click to add a new SSH connection.

Enter the complete ssh command, press Enter and use the default ssh configuration file without modification.

Click the remote window in the bottom left corner of VS Code again, click "Connect to Host...", select the configured SSH connection, and click "Connect" to establish the connection.

3. Modify the Default Access Directory

VS Code will open a new window and prompt that the connection is successful. Currently it points to the /root directory instead of the default working directory used by HyperAI. Click "Open Folder" in the left sidebar and switch to /openbayes/home to see the directory contents.

4. Install Additional Plugins to Support Jupyter File Execution

In the SSH remote login scenario, if you need to execute .ipynb files in the container, you need to install the corresponding plugin.

Create a new file main.ipynb. After double-clicking, Select Kernel will be displayed in the upper right corner of the page. Clicking it will prompt to install the plugin:

Follow the prompt and click "Install in SSH...".

After installation is complete, return to the main.ipynb page. You'll find that the default kernel has been selected in the upper right corner, and Python commands can now be executed.

I don't see any Chinese text in the image you've shared. The image shows a screenshot of VS Code with a Jupyter notebook interface. If you have Chinese text that you'd like me to translate to English, please provide it and I'll be happy to help translate it accurately and fluently.