Set a custom port for Simple Application Server

更新时间:
复制 MD 格式

When connecting to a Simple Application Server instance using Workbench, the default ports are 22 for Linux and 3389 for Windows. To enhance security, you can change the default remote connection port.

Prerequisites

  • The Simple Application Server instance must be in the Running state.

  • A password has been set for the instance. For more information, see Set or reset the instance password.

  • The custom port has been allowed in the instance's firewall. For more information, see firewall settings.

Step 1: Modify the remote connection port

Connect to the instance and modify the remote connection port in the SSH configuration file or the registry.

Linux

This section describes how to change the default remote port for a Linux instance, using CentOS 8.2 and CentOS 7.6 as examples.

  1. Use the default port to connect to the Linux server.

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

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

    1. Run the following command to edit the sshd_config file.

      sudo vi /etc/ssh/sshd_config
    2. In the sshd_config file, find the #Port 22 line and press i to enter edit mode.

      # If you want to change the port on a SELinux system, you have to tell
      # SELinux about this change.
      # semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
      #
      #Port 22
      #AddressFamily any
      #ListenAddress 0.0.0.0
      #ListenAddress ::
      HostKey /etc/ssh/ssh_host_rsa_key
      HostKey /etc/ssh/ssh_host_ecdsa_key
      HostKey /etc/ssh/ssh_host_ed25519_key
    3. Below #Port 22, add Port 24. This example uses port 24.

      Port 24
      #AddressFamily any
      #ListenAddress 0.0.0.0
      #ListenAddress ::
    4. Press the Esc key, enter :wq, and press Enter to save the file and exit edit mode.

  4. Run the following command to restart the sshd service. After the service restarts, you can use port 24 to connect to the Linux instance using SSH.

    • For CentOS 7 or later and Alibaba Cloud Linux 3:

      sudo systemctl restart sshd
    • For CentOS 6:

      /etc/init.d/sshd restart

Windows

This section describes how to change the default remote port for a Windows instance, using Windows Server 2022 Datacenter Edition as an example.

  1. Use the default port to connect by using Workbench (console).

  2. Modify the value of the PortNumber registry subkey.

    1. Press Win+R to open the Run dialog box, type cmd, and then press Ctrl+Shift+Enter to open Command Prompt as an administrator.

    2. In the command-line window, type regedit.

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

    4. In the list on the right, find and right-click the PortNumber registry entry, and select Modify.

      The default value of PortNumber is 0x00000d3d (3389).

    5. In the dialog box that appears, enter the new remote port number in the Value data text box, in the Base area, click Decimal, and then click OK.

  3. Find the RDP service name.

    1. In the command-line window, type services.msc to open the Services console.

    2. In the Services window, right-click Remote Desktop Services and select Attributes.

    3. On the General page in the pop-up window, find your Service Name TermService.

  4. In the Command Prompt window, run the following command to restart the RDP service.

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

Step 2: Connect using the custom port

Workbench

  1. Go to the Servers page in the Simple Application Server console.

  2. On the server card, click Connect to connect to the server remotely.

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

  3. In the pop-up Connect dialog box, select Workbench One-click Connect or Workbench Password Logon.

  4. Click Modify, enter your custom port in the text box, and click Confirm Modification.

    You can click Detect to verify that the port is open in the firewall. After confirming the port change, click Log on Now.

  5. Click Log on Now.

Third-party client

The procedure varies based on the instance's operating system:

  • Windows

    To connect to the instance, append the new port number to its remote address.

    远程访问服务器

    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.