All Products
Search
Document Center

Platform For AI:Use a proxy client to connect to a DSW instance

Last Updated:Apr 26, 2024

Data Science Workshop (DSW) of Platform for AI (PAI) provides a proxy client that allows you to remotely connect to a DSW instance from an on-premises host over Secure Shell (SSH). After the connection is established, you can develop machine learning algorithms by using Visual Studio Code (VS Code) or Terminal. This topic describes how to connect to a DSW instance over SSH by using a proxy client.

Prerequisites

Before you perform the operations that are described in this topic, make sure that the following requirements are met:

Usage notes

  • If your DSW instance is started before 12:00 on August 10, 2022 (UTC +8), stop the instance and then restart the instance to enable the SSH connection feature.

    Note

    You can go to the Interactive Modeling (DSW) page, find the DSW instance that you want to manage, and then view the service time of the instance in the Duration column to check whether the instance needs to be restarted. For more information, see Create DSW instances.

  • If you complete the configuration and restart a DSW instance, make sure that the following operations are performed before you remotely connect to the DSW instance:

    • If you created the DSW instance by using the public resource group, you must run the sudo service ssh start command in the terminal of the DSW instance to start the SSH service.

    • If you created the DSW instance by using a dedicated resource group and did not mount a dataset, perform the operations in this topic to reconfigure the public key of the server and enable password-free logon, or configure the password-based logon. If you have a dataset mounted, run the sudo service ssh start command in the terminal of the DSW instance to start the SSH service.

Step 1: Download and install the DSW proxy client

  1. Download the DSW proxy client file to the home directory.

    The home directory varies based on your operating system. The following section lists the home directories for different operating systems:

    • Windows operating system: the personal folder directory of the user. Example: C:\Users\<username>, or C:\users \<username>. Select a directory based on the actual scenario.

    • Linux operating system: /root (for root users) or /home/<username> (for standard users).

    • macOS: /Users/<username>.

    Replace <username> with the actual directory.

    Download URLs of different versions of the proxy client:

  2. Run the following command on the CLI to grant execute permissions on the downloaded client file. If you downloaded the client of the Windows X86-64 version, skip this step.

    chmod 755 <proxyclient>

    Replace <proxyclient> with the actual client file name.

  3. Generate a configuration file.

    1. Run one of the following commands:

      # macOS, Linux 
      ./proxyclient config
      # Windows 
       proxyclient.exe config
      Important

      If you use macOS, the Failed to open "proxyclient" because it is an unverified client error message may appear the first time you run the ./proxyclient command. In this case, we recommend that you modify the security and privacy settings of your macOS host to allow the proxy client to be run on the host.

    2. Follow the on-screen instructions to configure the path of the configuration file.

      Specify the name of the configuration file. The name can contain a path.

      Note
      • We recommend that you press the Enter key to use the default path and name of the configuration file. The default path is ~/.proxyclientconfig.

      • You can also specify a different path and name for the configuration file. For example, you can specify C:/Users/<username>/xxx/.proxyclientconfig for a Windows X86 64-bit operating system.

      • If you specify a custom path, you must set -c or --config-file to the custom path when you run the ./proxyclient add command in Step 4.

    3. Configure the RegionId, AccessKey ID, AccessKey Secret, and STSToken parameters as prompted.

      The following table describes the parameters.

      Parameter

      Description

      RegionId

      The region ID. For example, the ID of the China (Shanghai) region is cn-shanghai. For more information about other region IDs, see Regions and zones.

      Important

      This parameter specifies the ID of the region where the DSW instance resides.

      AccessKey ID

      The AccessKey pair of the Alibaba Cloud account. For more information about how to obtain the AccessKey ID and AccessKey secret of an Alibaba Cloud account, see Create an AccessKey pair.

      AccessKey Secret

      STSToken

      • If you log on to the instance by using an Alibaba Cloud account or a RAM user, you can leave this parameter empty.

      • If you assume a RAM role to log on to the instance and use temporary identity credentials, you must configure this parameter. For more information about how to obtain an STS token, see Obtain an STS token.

      Important

      Make sure that the STS token is valid.

Step 2: Configure the SSH authentication method

You can use an SSH key pair or a combination of an account and a password to connect to a DSW instance. After an authentication method is configured, you can click Save Image in the Actions column of the DSW instance to which you want to connect to save the instance configuration as an image. The added public key or password persists in the instance image and remains valid after the instance is restarted.

Method 1: Configure password-free logon (recommended)

  1. Generate an SSH key pair.

    1. Run the following command on the CLI of your on-premises host to generate the public and private key files required for password-free logon. By default, the generated key pair is an RSA key pair.

      ssh-keygen
    2. Specify file names for the key pair.

      • (Recommended) Press the Enter key to use the default file names. If you do not specify file names, the ~/.ssh/id_rsa private key file and the ~/.ssh/id_rsa.pub public key file are generated by default.

      • Optional. Specify custom file names. Example: example_id_rsa.

        Note

        If you specify custom file names, you must include the IdentityFile syntax in your ~/.ssh/config file to specify the path of the private key file in Step 3.

    3. Specify the passphrase parameter as prompted and save the parameter value to your on-premises host. The value of the passphrase parameter is used to connect to the DSW instance.

  2. Go to the DSW development environment.

    1. Log on to the PAI console.

    2. In the left-side navigation pane, click Workspaces. On the Workspaces page, click the name of the workspace of the model service that you want to manage.

    3. In the upper-left corner of the page, select the region where you want to use the service.

    4. In the left-side navigation pane, choose Model Development and Training > Interactive Modeling (DSW).

    5. Optional. On the Interactive Modeling (DSW) page, enter an instance name or a keyword in the search box to search for instances.

    6. Find the DSW instance and click Open in the Actions column.

  3. On the Terminal tab, run the following command. The setup_ssh.sh tool automatically downloads and installs the SSH server.

    wget https://dsw-resource.oss-cn-beijing.aliyuncs.com/tools/setup_ssh.sh
    bash setup_ssh.sh
  4. Configure the SSH public key as prompted and start the SSH server.

Method 2: Configure password-based logon

In Terminal of the DSW instance, perform the following operations to configure password-based access. For information about how to go to the DSW instance page, see Method 1: Configure password-free logon (recommended).

  1. On the Data Science Workshop page, click the TermInal tab in the top navigation bar. On the Welcome to DSW Terminal page, click Create Terminal.

  2. Specify the password for the root account.

    passwd root
  3. Modify the SSH configuration file to allow root account logon by using a private or public key.

    1. Open the SSH configuration file.

      vi /etc/ssh/sshd_config
    2. Modify #PermitRootLogin prohibit-password to PermitRootLogin yes and save the configuration file.

  4. Restart the SSH server to apply the settings.

    service ssh stop
    service ssh start

Step 3: Add a proxy for the DSW instance

  1. Go to the DSW page. For more information, see Create DSW instances.

  2. Follow the instructions in the following figure to view and copy the ID of the DSW instance.

    e08dad9ce3e2dc97cbebdea95b9cea14

  3. Run one of the following commands on the CLI of your on-premises host to add the DSW instance as an SSH target host:

    Replace <Instance ID> with the DSW instance ID that you obtained in Step 2.

    # Mac, Linux
    ./proxyclient add -i=<Instance ID>
    # Windows
    proxyclient.exe add -i=<Instance ID> 
  4. View the content of the .ssh/config file to make sure that the proxy setting is effective.

    # macOS, Linux 
    cat .ssh/config
    
    # Windows Use the CLI of your on-premises host to go to the home directory of the host and run the following command to check the content of the .ssh/config file. You can also double-click the .ssh/config file to open the file. 
    explorer .ssh\config
  5. Optional. If you use custom file names for the key pair, such as example_id_rsa, modify the ~/.ssh/config file and use the IdentityFile syntax to specify the path of the key files that are used to connect to the host.

    Host dsw-b7a2765b267e****
        HostName dsw-b7a2765b267e****
        User root
        ProxyCommand ~/proxyclient connect --region-id=cn-hangzhou --instance-id=dsw-b7a2765b267e**** --config-file=***
        ServerAliveInterval 30
        IdentityFile ~/.ssh/example_id_rsa

Step 4: Connect to the DSW instance

Use VS Code to establish a remote connection to the DSW instance

The specific procedure varies based on the VS Code version. Perform operations based on the VS Code version that you use. For more information, see Getting Started in the VS Code documentation.

  1. Open VS Code on your on-premises host and install the Remote-SSH extension based on the instructions in the following figure.

    SSH

  2. In the left-side navigation pane of VS Code, click the Remote explorer icon.

    SSH Targets

  3. Add the DSW instance to which you want to connect over SSH.

    1. Click the 新增 icon icon next to SSH to add the instance. In the field that appears, enter the ID of the DSW instance and press the Enter key.

      Remote

    2. Click and select the configuration file that you want to modify.

      配置文件

    3. In the Host added dialog box that appears in the lower-right corner of VS Code, click Connect.

      Connect

    4. Click Linux and select the operating system of the DSW instance.

      操作平台

    5. Enter the value of the passphrase parameter that you saved in Step 3 into the field, and press the Enter key.

      passphraseWhen the Welcome page of VS Code appears, the connection is established. You can start to code in VS Code by using the connected instance on your on-premises host. VS Code

  4. Next time you want to connect to the DSW instance, right-click the instance, select a connection method, and then configure parameters as prompted.

    连接方式

    After the remote connection is established, you can start to code by using the connected instance on your on-premises host.

Use a tool to establish a remote connection to the instance

Open a terminal tool such as an on-premises command-line tool and run the following command to connect to the DSW instance:

Replace <Instance ID> with the ID of the DSW instance.

ssh <Instance ID>

You can also use the scp command to copy files or directories between your on-premises host and the instance.

# Copy files from your on-premises host to the instance. 
scp local_file_path root@<DSW instance ID >:< remote_file_path>
# Copy directories from your on-premises host to the instance. 
scp -r local_dir root@<DSW instance ID >:< remote_dir>
# Copy files from the instance to your on-premises host. 
scp root@<DSW instance ID >:< remote_file_path> <local_file_path>
# Copy directories from the instance to your on-premises host. 
scp -r root@<DSW instance ID >:< remote_dir> <local_dir> 

References

Performance issues such as frequent reconnection and low speed may occur when you use a proxy client to connect to a DSW instance. To improve connection quality, we recommend that you directly connect to the DSW instance. For more information, see the following topics: