All Products
Search
Document Center

Platform For AI:Remote connection: Direct SSH connection

Last Updated:Jul 09, 2026

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.ebm in 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>\.ssh or C:\用户\<username>\.ssh

  • Linux: /root/.ssh for the root user, or /home/<username>/.ssh for 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.

Create a VPC, vSwitch, and security group

  1. On the DSW configuration page, click Create VPC.

    imageConfigure 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.

    image

  2. Go back to the DSW configuration page. For VPC Settings, select the VPC that you created.

  3. Click Create Security Group. Keep the default parameters and click OK. Go back to the DSW configuration page and set Security Group ID to the security group that you created.

    image

    Make sure the security group allows inbound access on port 22.

    image

Enable SSH

Turn on this switch and paste the contents of the public key file id_rsa.pub generated in Step 2 into the SSH Public Key text box. Click Add to add more public keys. Up to 10 public keys are supported.

Service Access and Port Configuration

After you turn on Enable SSH, an SSH service appears.

  • Listener Port: The port on which the service listens in the DSW instance. The default value is 22.

  • Service Access Method:

    • Access over VPC: This access method is supported by default. You can access DSW services from other terminals within the VPC, such as ECS instances.

    • Access over Internet: Select this option to enable public network access. You also need to configure the Public Network Access parameters.

  • Internet Access Port: The port used for public network access. This is the -p parameter in the SSH command. Example: 1024.

Public Network Access

Required for public network access. Select DNAT + EIP.

  • NAT Gateway: Required for public network access. Select the Internet NAT gateway created for the current VPC.

  • EIP: Required for public network access. Select the Elastic IP Address (EIP) created for the current NAT gateway.

To create a NAT gateway and an EIP, follow these steps:

Create a NAT gateway and an EIP

  1. Click Create NAT Gateway.

    image

    On the NAT gateway creation page, configure the parameters or use the default values, and then click Create EIP.

    image

  2. On the EIP creation page, configure the parameters or use the default values, and then click Buy Now.

  3. Go back to the NAT gateway creation page. For Elastic IP Address, select the EIP that you created, and then click Buy Now to create the NAT gateway.

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

  1. 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.

    Note

    If public network access isn't enabled in the SSH configuration, only the VPC access method is displayed.

  2. 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 1024
      Important

      The value 1024 for the -p parameter 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

    1. Open VS Code and install the Remote - SSH extension from the Extensions marketplace.

      image

    2. Click image in the lower-left corner to open the Remote-SSH dialog box. Select Connect to Host... > Add New SSH Host....

    3. 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

      image

    4. Click Open in the lower-right corner. When the connection succeeds, the status bar in the lower-left corner shows the remote host name.

      image

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

      image

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

      image

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

  1. Install the remote_ikernel tool on your local machine, then add a remote kernel.

    pip install remote_ikernel
    remote_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
  2. In VS Code, open a Notebook file. Click the kernel selector in the upper-right corner and select Remote Python from the search box.

    image

FAQ

Q: What's the difference between SSH direct connection and ProxyClient proxy?

Comparison between SSH direct connection and ProxyClient proxy

Option A: SSH direct connection (recommended)

Option B: ProxyClient proxy

Features

Requires VPC, NAT gateway, and other network components. Provides a faster and more stable connection.

No additional network components required. Connection speed and stability may be lower.

Supported instances

All instance types except those with specifications starting with ecs.ebm in public resource groups.

All instance types.

Authentication

Uses SSH public/private key authentication.

  1. Authenticate through ProxyClient with your Alibaba Cloud AccessKey.

  2. Then authenticate through SSH public/private key.

Access methods

  • Public network access (requires a NAT gateway and EIP).

  • Internal access within the user's VPC.

Public network access.

Configuration

Remote connection: Direct SSH connection

Remote connection: ProxyClient

How it works

PAI automatically creates DNAT rules on the NAT gateway to forward public SSH requests to the DSW instance.

All traffic is relayed through the PAI proxy server.

Billing

NAT gateways and EIPs are billed continuously, even when the DSW instance is stopped. Delete them when they're no longer needed.

No additional charges.

Q: How do I troubleshoot SSH connection failures, timeouts, or key rejections?

Troubleshoot the issue based on the following categories:

  • Public network connection failure

  • 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 -i parameter.

  • VS Code connection failure

    • Make sure the Remote - SSH extension 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.

View the public IP address

  1. On the DSW instance list page, click the instance name to open the instance configuration page.

  2. In the Network Information section, click Internet Access Gateway. You can find the IP address on the EIP page.

    image

    image

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.