Updated on 2023-10-11 GMT+08:00

ADB (Internet)

An EIP is bound to a server, not to the cloud phones virtualized from the server. When you access a cloud phone over the Internet, establish an SSH tunnel first. That is, use the ADB (Internet) method, which includes two steps: establishing an SSH tunnel, and accessing the cloud phone through ADB. For details about the SSH tunnel and ADB, see Basic Concepts.

Use a local device (recommended) or a cloud server to access your cloud phone. The local device can run Windows, Linux, Android, or macOS. This topic uses the Windows as an example.

Prerequisites

  • The cloud phone must be in the Running state.
  • If you want to use an IPv6 address to connect to a dual-stack cloud phone, ensure that your environment, such as your ECS, supports IPv6 addresses.

Preparations

Before establishing an SSH tunnel, ensure that the SSH service has been installed on the local device that will be used to access the cloud phone. (For details, see How Can I Know Whether the SSH Service Has Been Installed on My Local Device?) You also need to log in to the CPH console and complete the following preparations:

  1. Obtain the project ID of the region where the target cloud phone is located.
    The operations are as follows:
    1. Locate the username in the upper right corner, hover the mouse over it, and select My Credentials from the drop-down list.

    2. Choose API Credentials. In the Projects area, obtain the project ID of the region where the cloud phone to be accessed is located.

      Example: region CN East-Shanghai1

      If the project ID contains more than 32 characters, the first 32 characters are used as the username of the SSH tunnel to be established.

  2. Select an idle port on the local device to connect to the cloud phone.

    Run the netstat -an command to check whether the port is idle.

    As shown in the following figure, port 6667 is occupied (displayed as LISTENING) by another program, and port 1234 is idle.

  3. Obtain the listening IP address of the cloud phone, that is, the internal IP address and port number of the cloud phone.

    The operations are as follows:

    1. On the CPH console, in the left navigation pane, choose Instances, and click the name of the target cloud phone.

    2. In the Application Port area, obtain the listening IP address of the cloud phone.

      • If you have customized the application port in Advanced Settings when purchasing a server, the port information is displayed. The authentication mode of the SSH tunnel is the same as that of using the default ADB port. You only need to replace the listening IP address of the cloud phone with the listening IP address of the cloud phone on the corresponding port.
      • If you select Internet access when customizing the application port, the public access address of the port is displayed. You can access the cloud phone over the Internet and this port. However, stay alert to security risks.
      • If you select Automatically-assigned IPv6 address when purchasing a cloud phone server, the Instance Listening IP Address column will contain two lines of data, and the IPv6 IP address is in the second line. If you want to connect to the cloud phone through an IPv6 address, use this one.
  4. Obtain the public IP address of the server.

    The operations are as follows:

    On the CPH console, choose Servers in the left navigation pane, locate the target server, and obtain the value of IP Address.

    • If there are multiple servers, identify the server from which the cloud phone was virtualized by name. For example, if the cloud phone name is cph-test-1-00001, the corresponding server name is cph-test-1.
    • If you select Automatically-assigned IPv6 address when purchasing a cloud phone server, you can use the IPv6 address of the server to establish a tunnel to connect to the cloud phone. To view the public IPv6 address, go to the server details page or view the Server Listening IP Address column in the Application Port area in the previous step.
  5. Obtain the local path for storing the private key file corresponding to the server key pair, that is, the local path for storing the private key file when the key pair is created in 6, for example, C:/Users/Administrator/Downloads/KeyPair-a49c.pem.
    The path is case insensitive.

    If the private key file corresponding to the server key pair is lost, see What Can I Do If the Private Key File Is Lost?

Step 1 Establish an SSH Tunnel

  1. Open the CLI on your local device. The following uses Windows 10 as an example:

    Press Win+R, enter cmd in the Run dialog box, and press Enter.

  2. Run the following command to establish an SSH tunnel:

    ssh -L Local idle port:Cloud phone listening IP address: SSH tunnel username@Public IP address -i Private key file path -o ServerAliveInterval=30 -Nf

    The parameters are described as follows:

    • Local idle port: indicates any selected local idle port. The port is mapped to the cloud phone application port. For details about how to obtain the local idle port, see 2.
    • Cloud phone listening IP address: indicates the private IP address and port number of the cloud phone. For details about how to obtain the private IP address and port number, see 3.
    • SSH tunnel username: indicates the project ID of the region where the cloud phone is located. For details about how to obtain the project ID, see 1.
    • Public IP address: indicates the public IP address of the cloud phone server. For details about how to obtain the public IP address, see 4.
    • Private key file path: indicates the local path for storing the private key file corresponding to the server key pair. For details about how to obtain the local path, see 5.

    Assume that the local idle port is 1234, the listening IP address of the cloud phone is 10.237.0.61:5555, the SSH tunnel username is 05e1aexxx, the public IP address is xxx.xxx.xxx.xxx, and the private key file path is C:\Users\Administrator\Downloads\KeyPair-a49c.pem. Run the following command:

    ssh -L 1234:10.237.0.54:5555 05e1aexxx@xxx.xxx.xxx.xxx -i C:\Users\Administrator\Downloads\KeyPair-a49c.pem -o ServerAliveInterval=30 -Nf

    This command sets up an SSH tunnel from the local PC to the cloud phone. The tunnel uses local port forwarding and listens to port 1234 of the local PC. When port 1234 of the local PC is accessed, the communication data is forwarded to port 5555 of the cloud phone.

    After the command is executed, the SSH program forwards packets through the tunnel in the background. If no error is reported, or "Authorized users only. All activities may be monitored and reported." is displayed, the SSH tunnel is successfully established.

    If you select Automatically-assigned IPv6 address when purchasing a cloud phone server, you can use the IPv6 address of the server to establish a tunnel to connect to the cloud phone. The command structure is the same as that for an IPv4 address. The following is an example:

    ssh -L 1234:[fd00::aed:96]:5555 05e1aexxx@ xxx:xxx:xxx:xxx -i C:\Users\Administrator\Downloads\KeyPair-a49c.pem -o ServerAliveInterval=30 -Nf

    For details about how to troubleshoot SSH tunnel establishment faults, visit the following links:

Step 2 Access the Cloud Phone Through ADB

  1. Download ADB.

    Visit https://developer.android.com/studio/releases/platform-tools, switch the language to English in the upper right corner, and choose Download SDK Platform-Tools for Windows.

    In the displayed dialog box, select the I have read and agree with the above terms and conditions check box, and click DOWNLOAD ANDROID SDK PLATFORM-TOOLS FOR WINDOWS.

    If you cannot access the preceding website, click the following link to download ADB:

    https://dl.google.com/android/repository/platform-tools-latest-windows.zip

  2. Decompress the obtained platform-tools_r29.0.5-windows.zip file to a specified directory, for example, C:\Users\Administrator\Downloads.

    Version number 29.0.5 in the platform-tools_r29.0.5-windows.zip file is only an example.

  3. Open the CLI and go to the C:\Users\Administrator\Downloads\platform-tools directory.

    In Step 1 Establish an SSH Tunnel, if message "Authorized users only. All activities may be monitored and reported." is displayed, do not close the CLI, and open another CLI to perform this step.

    cd C:\Users\Administrator\Downloads\platform-tools

  4. Run the following ADB command to access the cloud phone:

    adb connect 127.0.0.1:Local idle port

    Local idle port is the idle port used in 2.

    Example: adb connect 127.0.0.1:1234

  5. Run the adb devices command to check whether the current port is connected.