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:
A DSW instance is created. For more information, see Create DSW instances.
An AccessKey ID and an AccessKey secret are obtained. For more information, see Create an AccessKey pair.
If you use a RAM user or RAM role to connect to the DSW instance over SSH, you must grant the RAM user or RAM role the permissions to access the DSW instance. For more information, see Grant the permissions that are required to use DSW.
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.
NoteYou 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 password-based logon. If you mounted a dataset, 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
Download the DSW proxy client file to the home directory.
The home directory varies based on your operating system. The following section describes 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:
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.
Generate a configuration file.
Run one of the following commands:
# macOS, Linux ./proxyclient config # Windows proxyclient.exe config
ImportantIf 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.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.
NoteTo use the default path and name of the configuration file, press the Enter key. The default path is
~/.proxyclientconfig
.You can 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.
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 information about other region IDs, see Regions and zones.
ImportantThis parameter specifies the ID of the region where the DSW instance resides.
AccessKey ID
The AccessKey pair of the Alibaba Cloud account. For 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 use 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.
ImportantMake 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 you configure an authentication method, 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 is included in the instance image and remains valid after the instance is restarted.
Method 1: Configure password-free logon (recommended)
Generate an SSH key pair.
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
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 automatically generated.Optional. Specify custom file names. Example: example_id_rsa.
NoteIf you specify custom file names, you must use the IdentityFile syntax in your
~/.ssh/config
file to specify the path of the private key file in Step 3.
Configure 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.
Go to the DSW development environment.
Log on to the PAI console.
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.
In the upper-left corner of the page, select the region where you want to use the service.
In the left-side navigation pane, choose
.Optional. On the Interactive Modeling (DSW) page, enter an instance name or a keyword in the search box to search for instances.
Find the DSW instance and click Open in the Actions column.
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
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).
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.
Specify the password for the root account.
passwd root
Modify the SSH configuration file to enable root account logon by using a private or public key.
Open the SSH configuration file.
vi /etc/ssh/sshd_config
Change
#PermitRootLogin prohibit-password
toPermitRootLogin yes
and save the configuration file.
Restart the SSH server to apply the settings.
service ssh stop service ssh start
Step 3: Add a proxy for the DSW instance
Go to the DSW page. For more information, see Create DSW instances.
Follow the instructions in the following figure to view and copy the ID of the DSW instance.
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>
View the content of the .ssh/config file to make sure that the proxy setting is in effect.
# 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
Optional. If you use custom file names for the key pair, such as example_id_rsa, modify the
~/.ssh/config
file and use theIdentityFile
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.
Open VS Code on your on-premises host and install the Remote-SSH extension based on the instructions in the following figure.
In the left-side navigation pane of VS Code, click the icon.
Add the DSW instance to which you want to connect over SSH.
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.
Click and select the configuration file that you want to modify.
In the Host added dialog box that appears in the lower-right corner of VS Code, click Connect.
Click Linux and select the operating system of the DSW instance.
Enter the value of the passphrase parameter that you saved in Step 3 into the field, and press the Enter key.
When 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.
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 coding 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: