All Products
Search
Document Center

Simple Application Server:Set a custom port to connect to a simple application server

Last Updated:Aug 01, 2024

When you connect to a simple application server by using Workbench, by default port 22 is used for Linux servers and port 3389 is used for Windows servers. To improve system security, you can modify the default remote connection port.

Prerequisites

  • The simple application server to which you want to connect is in the Running state.

  • A password is set for the simple application server. For more information, see Set or reset server passwords.

  • A custom firewall rule is created for the simple application server and the custom port that you want use to connect to the simple application server is enabled for the simple application server. For more information, see Manage a firewall.

Step 1: Modify the remote connection port

You must connect to the simple application server and modify the remote connection port in the SSH configuration file or registry.

Modify the remote connection port of a Linux server

In this example, CentOS 8.2 and CentOS 7.6 simple application servers are used to describe how to modify the default remote connection port of a Linux simple application server.

  1. Use the default port 22 to connect to the simple application server. For more information, see connect to a Linux server.

  2. Run the following command to back up the sshd_config service configuration file.

    sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config_bak
  3. Modify the sshd configuration file.

    1. Run the following command to modify the sshd_config configuration file.

      sudo vi /etc/ssh/sshd_config
    2. Find the #Port 22 line in the sshd_config file and press the I key to enter edit mode.

      image

    3. Enter Port 24 below #Port 22 to use Port 24 as the custom port in the following example.

      image

    4. Press the Esc key, enter :wq, and then press the Enter key to save and close the file.

  4. Run one of the following commands to restart sshd. After you restart sshd, you can use port 24 to log on to the Linux server over the SSH protocol.

    • If the simple application server runs CentOS 7 or later or Alibaba Cloud Linux 3, run the following command:

      sudo systemctl restart sshd
    • If the simple application server runs CentOS 6, run the following command:

      /etc/init.d/sshd restart

Modify the remote connection port of a Windows server

In this example, a simple application server that runs Windows Server 2022 Datacenter is used to describe how to modify the default remote connection port of a Windows simple application server.

  1. Use the default port 3389 to connect to the simple application server by using Workbench. For more information, see Use Workbench to connect to the server in the Simple Application Server console.

  2. Modify the value of the PortNumber registry subkey.

    1. Press Win+R to open the running dialog box, enter cmd, press Ctrl + Shift + Enter to log on to the server as an administrator.

    2. Enter regedit in the command line window.

    3. Go to HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp.

    4. Find and right-click PortNumber in the right list, and select Modify...

    5. In the dialog box that appears, enter a new remote connection port number in the Value Data field, click Decimal in the Base section, and then click OK.

  3. Queries the name of the RDP service.

    1. Enter services.msc on the command line page to open the service interface.

    2. On the Services page, right-click Remote Desktop Services and select Properties.

    3. On the Regular page, click your Service NameTermService.

  4. In the CLI, run the following command to restart the RDP service:

    # Replace TermService with the name of your service. 
    net stop TermService && net start TermService

Step 2: Use the custom port to connect to the simple application server

On Workbench

  1. Log on to the Simple Application Server console.

  2. In the left-side navigation pane, click Servers.

  3. In the card of the server, click Connect to connect to the server.

    You can also click the server ID in the server card to connect to the server on the Remote Connection tab.

  4. In the Connect dialog box, select Connect with One-click on Workbench or Password-based Logons on Workbench.

  5. Click Modify, enter the custom port number that you set in the field, and then click Confirm to modify.

  6. Click Log on Now.

On a third-party client

You can choose the corresponding operation based on the operating system of the server:

  • Windows

    Connect to the instance. In the Remote Desktop Connection dialog box, enter <IP address of the instance>:<New port number> in the Computer field and click Connect to connect to the instance.

    远程访问服务器

    Note

    Mac Remote Desktop Connection can only be used to connect to the instance over the default port 3389.

  • Linux

    Use an SSH client to connect to the instance to check whether traffic over the new port is allowed.

    Enter the new port number in the Port field. In this example, enter 1022.输入修改后的端口号

    Note

    After the port number is changed, you cannot use the default port 22 to connect to the instance.