SSH direct connection is the recommended way to connect to a DSW instance from a local terminal or VS Code. It provides a stable and fast connection.
Limitations
-
Unsupported instance types:
Resource specifications that start with
ecs.ebmin a public resource group don't support SSH remote connections. -
Public network connection limit:
When you connect to a DSW instance over the public network, PAI automatically creates DNAT rules on the NAT gateway. No manual configuration is required.
Each NAT gateway supports up to 100 DNAT rules, which means up to 100 DSW instances can connect simultaneously. For more quota information, see Quotas.
Billing
Public network connections to DSW instances require a NAT gateway, an Elastic IP address (EIP), or a Network Load Balancer (NLB). NAT gateways, EIPs, and NLBs are billed independently and continue to incur charges even when the DSW instance is stopped. Delete these resources when they're no longer needed.
Procedure
Step 1: Enable internal DNS resolution
Activate Private DNS. DSW instances are deployed in a VPC, and SSH connections rely on internal DNS to resolve instance IP addresses. Enable internal DNS resolution before connecting.
Step 2: Generate an SSH public key
Run the following command on your client to generate a public key. You'll be prompted to enter a passphrase. If you plan to use the remote_ikernel tool (see the example scenario in this topic), skip the passphrase by pressing Enter.
Generate a public key in the default directory (recommended)
Run the following command:
ssh-keygen
This command generates a public key (id_rsa.pub) and a private key (id_rsa) in the following default directories. If an SSH key pair already exists, the files are overwritten.
Windows:
C:\Users\<username>\.sshorC:\用户\<username>\.sshLinux:
/root/.sshfor the root user, or/home/<username>/.sshfor other users.macOS:
/Users/<username>/.ssh
Generate a public key in a custom directory
Run the following command:
ssh-keygen -f /your/path/example_rsa # Generates example_rsa.pub and example_rsa in /your/path
Step 3: Configure SSH parameters for the DSW instance
Configure the following network parameters when you Create a DSW instance.
For an existing instance, click Change Settings to modify the corresponding parameters, and then click OK to apply the changes.
|
Parameter |
Description |
|
Virtual Private Cloud, vSwitch ID, Security Group |
If you create a DSW instance with public resources, configure Virtual Private Cloud, vSwitch ID, and Security Group. For step-by-step instructions, see Create a VPC and vSwitch and Manage security groups. The VPC and security group must be in the same region as the DSW instance. Important
Make sure the security group's inbound rules allow TCP traffic on port 22 from your client IP address. |
|
Enable SSH |
Turn on this switch and paste the contents of the public key file |
|
Service Access and Port Configuration |
After you turn on Enable SSH, an SSH service appears.
|
|
Public Network Access |
Required for public network access. Select DNAT + EIP.
To create a NAT gateway and an EIP, follow these steps: Alternatively, select NLB. When you create an NLB instance, set Instance Network Type to Public and select the same VPC as the DSW instance. For more information, see Get started with NLB for IPv4 load balancing. Note
If multiple DSW instances share the same DNAT and EIP (or NLB), use a different public access port for each instance. |
Step 4: Install SSH server
In the DSW instance terminal, run the following command to check whether the SSH service is running.
Official prebuilt images and custom images derived from them have SSH server installed and started by default.
service ssh status
If the SSH service isn't running, run the following commands in the DSW instance terminal to install SSH server.
sudo apt-get update
sudo apt-get install openssh-server
sudo service ssh start
If sudo isn't available, run apt-get install sudo first, then retry.
Step 5: Connect to the DSW instance
-
View the connection methods.
On the DSW page, click the instance name to open the instance details page. In the Instance Settings tab, go to the Network Settings section to find the public network access method and the VPC access method.
NoteIf public network access isn't enabled in the SSH configuration, only the VPC access method is displayed.
-
Connect to the DSW instance.
Connect by using SSH
-
Public network access
In a local command-line tool or terminal, use the public network access method obtained in the previous step to connect to the DSW instance.
ssh root@xx.xx.xx.xx -p 1024 # If the private key isn't in the default path, specify its location ssh -i /your/path/example_rsa root@xx.xx.xx.xx -p 1024ImportantThe value 1024 for the
-pparameter is the public access port configured for SSH. -
VPC access
From another terminal within the VPC (such as an ECS instance), use the VPC access method obtained in the previous step to connect to the DSW instance.
ssh root@dsw-notebook-xxxx.dsw-xxxx.dsw.pai.alibaba.com -p 22 # If the private key isn't in the default path, specify its location ssh -i /your/path/example_rsa root@dsw-notebook-xxxx.dsw-xxxx.dsw.pai.alibaba.com -p 22
Connect by using VS Code
-
Open VS Code and install the Remote - SSH extension from the Extensions marketplace.

Click
in the lower-left corner to open the Remote-SSH dialog box. Select Connect to Host... > Add New SSH Host....-
Enter the SSH connection command.
ssh root@xx.xx.xx.xx -p 1024 # If the private key isn't in the default path, specify its location ssh -i /your/path/example_rsa root@xx.xx.xx.xx -p 1024
-
Click Open in the lower-right corner. When the connection succeeds, the status bar in the lower-left corner shows the remote host name.

-
Open a folder in the DSW instance to start developing and debugging remotely.

-
During runtime, connect to a kernel in the DSW instance.

-
Example: Run local Notebook code on a DSW instance
Prerequisites
Complete Steps 1--4 in this topic. When generating the SSH key pair, don't set a passphrase.
Procedure
-
Install the remote_ikernel tool on your local machine, then add a remote kernel.
pip install remote_ikernelremote_ikernel manage --add \ --kernel_cmd="ipython kernel -f {connection_file}" \ # No modification needed --name="Remote Python" \ --interface=ssh \ --host=root@*.*.*.*:1024 # Replace with your host address. If the private key isn't in the default path, use --host="-i /your/path/example_rsa root@*.*.*.*:1024"If you see the following output, the remote kernel has been added successfully.
Added kernel ['rik_ssh_root_121_40_*_*_1024_remotepython']: SSH root@121.40.*.*:1024 Remote Python.To view the remote kernel configuration, run the following command.
remote_ikernel manage --show -
In VS Code, open a Notebook file. Click the kernel selector in the upper-right corner and select Remote Python from the search box.

FAQ
Q: What's the difference between SSH direct connection and ProxyClient proxy?
Q: How do I troubleshoot SSH connection failures, timeouts, or key rejections?
Troubleshoot the issue based on the following categories:
-
Public network connection failure
Make sure the security group's inbound rules allow TCP traffic on port 22 from your client IP address.
If the VPC has multiple Internet NAT gateways, see Deploy single-AZ NAT gateways for high availability to check the routing relationship between NAT gateways, vSwitches, and route tables.
If there's only one NAT gateway, use the self-service troubleshooting tool to analyze network reachability.
-
VPC internal connection failure
Make sure the client and the DSW instance are in the same VPC, and that internal DNS resolution is enabled.
If you use a custom image, make sure that SSH Server is installed and started. For more information, see Step 4: Install SSH server.
Make sure the security group's inbound rules allow TCP traffic on port 22.
-
Permission denied (key rejected)
Make sure the full contents of the public key (
id_rsa.pub) are added to the SSH configuration of the DSW instance.Make sure the private key used in the SSH command matches the public key. If the private key isn't in the default path (
~/.ssh/id_rsa), specify it with the-iparameter.
-
VS Code connection failure
Make sure the
Remote - SSHextension is installed, and the SSH command is entered completely (for example,ssh root@xx.xx.xx.xx -p 1024).Test the connection in a local terminal first. After the basic connection succeeds, troubleshoot the VS Code configuration.
If you see a "pipe does not exist" error, restart VS Code or reinstall the Remote - SSH extension.
Q: Can I use PyCharm or other local IDEs to connect to a DSW instance?
Yes. All features based on the native SSH protocol are supported. When you use PyCharm, it automatically downloads and installs a server-side component on the DSW instance. Therefore, the DSW instance must have public network access.
Q: How do I find the public IP address of an instance?
If a NAT gateway is configured, follow these steps to find the public IP address.
Q: Does a DSW instance support multiple SSH users?
By default, DSW instances only support SSH login as the root user. Creating multiple users with isolated SSH access isn't officially supported. You can create users manually within the instance, but this configuration is unsupported.
Q: I can't see my workspace files after connecting through a local IDE. What should I do?
After logging in via SSH, the default directory is the root user's home directory (/root). Workspace files are typically on a mounted data disk, such as /mnt/workspace. In VS Code, go to File > Open Folder and select the correct directory.
References
If this approach doesn't suit your scenario or you don't want to configure additional network components, try ProxyClient for remote connections.
Configure the VPC name, IPv4 CIDR block, and vSwitch information. Keep the default values for other parameters, and then click OK to create the VPC and vSwitch.





