All Products
Search
Document Center

Platform For AI:Remote connection: Direct SSH connection

Last Updated:Aug 26, 2026

Direct SSH connection is the recommended way to connect to a DSW instance from a local terminal or VS Code. Direct SSH connections are faster and more stable than ProxyClient connections.

Limitations

  • Unsupported instance types

    In public resource groups, instance types whose names start with ecs.ebm don't support direct SSH connections.

  • Public network connection limits

    When you connect to a DSW instance over the public network, PAI automatically configures DNAT rules on each Internet NAT gateway. No manual configuration is required.

    Each Internet NAT gateway supports a maximum of 100 DNAT rules. Therefore, a maximum of 100 DSW instances can connect at the same time. For more information about quotas, see Quotas.

Billing

Public network access to a DSW instance requires a NAT gateway, an Elastic IP address (EIP), or an Network Load Balancer (NLB). NAT gateways, EIPs, and NLBs are billed independently. Charges continue to accrue even after the DSW instance is stopped. Delete these resources promptly when you no longer need them.

Implementation steps

Step 1: Enable private DNS resolution

DSW instances are deployed in virtual private clouds (VPCs), and SSH connections rely on private DNS to resolve instance IP addresses. Enable private DNS resolution before you connect to a DSW instance. For more information, see Activate Private DNS.

Step 2: Generate an SSH key pair

Run the following command on your client to generate an SSH key pair. When prompted, set a passphrase for the key pair. If you plan to use remote_ikernel to connect to the instance (see the scenario example in this topic), leave the passphrase empty and press Enter.

Generate the key pair in the default path (recommended)

Run the following command:

ssh-keygen

After the command runs, a public key (id_rsa.pub) and a private key (id_rsa) are generated in the following directories. If an SSH key pair already exists, the existing files are overwritten. The default paths vary by operating system:

  • Windows: the C:\Users\<username>\.ssh directory.

  • Linux: the /root/.ssh directory for the root user, or the /home/<username>/.ssh directory for standard users.

  • macOS: the /Users/<username>/.ssh directory.

Generate the key pair 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 settings for the DSW instance

When you Create a DSW instance, configure the following network parameters.

For an existing instance, click Change Settings to modify the parameters, and then click OK to apply the changes.

Parameter

Description

VPC Settings, vSwitch, Security Group

A VPC Settings, a vSwitch, and a Security Group are required to create a DSW instance in a public resource group. You can create these resources by following the steps below. For more information, see Create a VPC and vSwitches and Manage security groups. The VPC and the security group must be in the same region as the DSW instance.

Important

Make sure the inbound rules of the security group allow traffic on TCP port 22 from your client IP address.

Steps to create a VPC, a vSwitch, and a security group

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

    imageConfigure the VPC name, IPv4 CIDR block, and vSwitch information. Keep the other parameters at their default values, and then click OK to create the VPC and the vSwitch.

    image

  2. Return to the DSW configuration page and select the newly created VPC for VPC Settings.

  3. Click Create Security Group, keep the default values, and then click Confirm. Return to the DSW configuration page and set Security Group ID to the newly created security group.

    image

    Make sure the inbound rules of the security group allow traffic on TCP port 22.

    image

Enable SSH

Turn on the switch, and then copy the content of the public key file id_rsa.pub generated in Step 2 to the SSH Public Key text box. Click Add to add the public keys of multiple clients. A maximum of 10 public keys are supported.

Service Access and Port Configuration

After you turn on the Enable SSH switch, a service named SSH appears.

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

  • SSH Access Method:

    • SSH Access over VPC: supported by default. You can access services in the DSW instance from other terminals in the VPC, such as ECS instances.

    • SSH Access over Internet: select this option to add public network access. You must also configure the parameters of Public Network Access.

  • Internet Access Port: the port that allows access from the public network. This port is the value of the -p parameter in SSH commands for public network access. Example: 1024.

Public Network Access

Configure this parameter if public network access is required. 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:

Steps to create a NAT gateway and an EIP

  1. Click Create NAT Gateway.

    image

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

    image

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

  3. Return to the NAT gateway creation page, select the newly created EIP for Elastic IP Address Instance, and then click Buy Now to create the NAT gateway.

You can also use an NLB instead. When you create the NLB instance, set Instance Network Type to Internet and select the same VPC as the current DSW instance. For more information, see Get started with NLB for IPv4 load balancing.

Note

If multiple DSW instances share the same DNAT rule and EIP (or NLB), use different public access ports.

Step 4: Install the SSH server

Official base images and custom images derived from them have the SSH server installed and started by default.

In the terminal of the DSW instance, run service ssh status to check the service status, or run pgrep sshd to check whether the sshd process exists. If the SSH service isn't running, run the following commands to install the SSH server.

Note

The Ready status of SSH in the console indicates only that the configuration is complete. It doesn't mean that the sshd process is running. Run pgrep sshd to confirm.

sudo apt-get update
sudo apt-get install openssh-server
sudo service ssh start

If the sudo command isn't found, run apt-get install sudo first, and then retry the preceding commands.

On CentOS or Red Hat Enterprise Linux (RHEL) systems, run yum install openssh-server or dnf install openssh-server.

Step 5: Connect to the DSW instance

  1. View the access methods.

    On the DSW page, click the instance name to go to the instance details page. In the Instance Settings tab, find the Network Settings section and view the public access method and the VPC access method.

    Note

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

  2. Connect to the DSW instance.

    Connect by using SSH

    • Public network access

      From your local command line or another terminal, connect to the DSW instance by using the public access method from Step 1.

      ssh root@xx.xx.xx.xx -p 1024 
      # If the private key is not in the default path, specify the key location
      ssh -i /your/path/example_rsa root@xx.xx.xx.xx -p 1024
      Important

      In the preceding commands, the -p parameter specifies the public access port configured for SSH. In this example, the port is 1024.

    • VPC access

      From another terminal in the VPC, such as an ECS instance, connect to the DSW instance by using the VPC access method from Step 1.

      ssh root@dsw-notebook-xxxx.dsw-xxxx.dsw.pai.alibaba.com -p 22
      # If the private key is not in the default path, specify the key location
      ssh -i /your/path/example_rsa root@dsw-notebook-xxxx.dsw-xxxx.dsw.pai.alibaba.com -p 22

    Connect from local VS Code

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

      After the installation is complete, open the Command Palette, enter remote-ssh, and choose the Remote-SSH: Connect to Host... command to start the remote connection.

    2. Click image in the lower-left corner to open the Remote-SSH dialog box, and then 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 is not in the default path, specify the key location
      ssh -i /your/path/example_rsa root@xx.xx.xx.xx -p 1024
    4. Click Open in the lower-right corner. The connection status appears in the lower-left corner.

    5. Open a directory in the DSW instance to start remote development and debugging.

      Click the Explorer icon in the activity bar on the left, click the Open Folder button, enter /mnt/workspace in the Open File or Folder dialog box, and then click OK to open the directory.

    6. To run code, connect to a kernel in the DSW instance.

      In the Select a Jupyter Kernel drop-down list at the top of VS Code, select the recommended Python 3 (ipykernel) kernel.

Scenario: Run a local notebook on a DSW instance

Prerequisites

Complete Steps 1 through 4 in this topic to configure the direct SSH connection. When you generate the SSH key pair, leave the passphrase empty.

Procedure

  1. From your local terminal, install remote_ikernel and add a remote kernel.

    pip install remote_ikernel
    remote_ikernel manage --add \
    --kernel_cmd="ipython kernel -f {connection_file}" \  # No changes required
    --name="Remote Python" \
    --interface=ssh \
    --host=root@*.*.*.*:1024  # Replace this with your host address. If the private key is not in the default path, use --host="-i /your/path/example_rsa root@*.*.*.*:1024"

    If the following message appears, the remote kernel is added.

    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 on your local machine, open a notebook file and switch the kernel in the upper-right corner. Search for Remote Python and select it.

FAQ

Q: What are the differences between direct SSH connection and ProxyClient proxy?

Differences between direct SSH connection and ProxyClient proxy

Option A: Direct SSH connection (recommended)

Option B: ProxyClient proxy

Features

Requires network components such as a VPC and a NAT gateway. Provides faster and more stable connections.

Requires no additional network components, but connection speed and stability may be lower.

Supported instances

All instance types except those whose names start with ecs.ebm in public resource groups.

All instance types.

Authentication method

SSH public key or private key authentication.

  1. Authenticate by entering your Alibaba Cloud AccessKey pair in ProxyClient.

  2. Then authenticate with an SSH public key or private key.

Access methods

  • Access over the public network (requires a NAT gateway and an EIP).

  • Access over the internal network within your VPC.

Access over the public network.

Configuration method

Remote connection: Direct SSH connection

Remote connection: ProxyClient

How it works

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

All traffic is forwarded through the PAI proxy server.

Billing reminder

For public network access, the NAT gateway and EIP continue to generate charges even after the DSW instance is stopped. Delete them when you no longer need them.

This configuration incurs no additional charges.

Q: How do I troubleshoot SSH connection failures, timeouts, or key rejection when I connect to a DSW instance?

Troubleshoot the issue by category:

  • Public network connection failures

    • Make sure the inbound rules of the security group allow traffic on TCP port 22 from your client IP address.

    • If multiple Internet NAT gateways exist in the VPC, see Deploy single-AZ NAT gateways for high availability to check the routing relationships among the NAT gateways, vSwitches, and route tables.

    • If only one NAT gateway exists, use self-service troubleshooting to analyze network connectivity.

  • VPC connection failures

    • Make sure the client and the DSW instance are in the same VPC. Run the dig command to test DNS resolution of the VPC domain name of the DSW instance. If NXDOMAIN is returned, DNS resolution isn't working. Check the private DNS settings of the VPC.

    • If you use a custom image, make sure the SSH service is installed and started. For more information, see Step 4: Install the SSH server.

    • Make sure the inbound rules of the security group allow traffic on TCP port 22.

    • Run ssh -v root@IP -p port to get detailed connection information. Connection timed out indicates a security group or network connectivity issue. Connection refused indicates that the port isn't listening (sshd isn't running). Connection reset indicates an authentication issue.

  • Key rejection (Permission denied)

    • Make sure the public key (the entire content of id_rsa.pub) is 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 by using the -i parameter.

    • Check whether the permissions of the ~/.ssh/authorized_keys file are 600. Run ls -l ~/.ssh/authorized_keys to verify. Incorrect permissions cause SSH to reject the public key.

  • VS Code connection failures

    • Make sure the Remote - SSH extension is installed and that you entered a complete SSH command, such as ssh root@xx.xx.xx.xx -p 1024.

    • Test the connection by running the SSH command in a local terminal. After the basic connection works, check the VS Code configuration.

    • If an error about a nonexistent pipe appears, restart VS Code or reinstall the Remote - SSH extension.

Q: Can I use a local IDE such as PyCharm to remotely connect to a DSW instance?

All features based on the SSH protocol are supported. When you connect by using PyCharm, PyCharm automatically downloads and installs the server-side components on the DSW instance. Therefore, the DSW instance must have public network access.

Q: How do I view the public IP address of an instance?

If an Internet NAT gateway is configured, view the public IP address by following these steps:

Steps to view the public IP address

  1. On the DSW instance list page, click the instance name to go to the instance details page.

  2. Find the Network Information section and click Internet Access Gateway. The IP address is displayed on the EIP instance page.

    The IP Address field in the Basic Information section of the instance details page shows the public IP address.

Q: Does a DSW instance support multiple users with separate SSH logins?

By default, a DSW instance provides only the root user for SSH logins. DSW doesn't support creating multiple independent users with isolated SSH logins. You can manually create additional users within the instance, but this isn't an officially supported practice.

Q: Why can't I see workspace files when I connect to a DSW instance from a local IDE such as VS Code or PyCharm?

After an SSH login, the default directory may be the home directory of the root user (/root). Workspace files are usually stored in a directory on the mounted data disk, such as /mnt/workspace. In VS Code, choose File > Open Folder to open the correct working directory.

References

  • If this method doesn't fit your scenario or you don't want to configure additional network components, use ProxyClient to connect remotely.