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.
-
Use the default port to connect to the Linux server.
-
Run the following command to back up the
sshd_configfile.sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config_bak -
Edit the sshd configuration file.
-
Run the following command to edit the
sshd_configfile.sudo vi /etc/ssh/sshd_config -
In the
sshd_configfile, find the#Port 22line and pressito 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 -
Below
#Port 22, addPort 24. This example uses port24.Port 24 #AddressFamily any #ListenAddress 0.0.0.0 #ListenAddress :: -
Press the
Esckey, enter:wq, and press Enter to save the file and exit edit mode.
-
-
Run the following command to restart the sshd service. After the service restarts, you can use port
24to 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.
-
Use the default port to connect by using Workbench (console).
-
Modify the value of the PortNumber registry subkey.
-
Press
Win+Rto open the Run dialog box, typecmd, and then pressCtrl+Shift+Enterto open Command Prompt as an administrator. -
In the command-line window, type
regedit. -
Navigate to
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp. -
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). -
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.
-
-
Find the RDP service name.
-
In the command-line window, type
services.mscto open the Services console. -
In the Services window, right-click Remote Desktop Services and select Attributes.
-
On the General page in the pop-up window, find your Service Name
TermService.
-
-
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
-
Go to the Servers page in the Simple Application Server console.
-
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.
-
In the pop-up Connect dialog box, select Workbench One-click Connect or Workbench Password Logon.
-
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.
-
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.
NoteMac 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.
NoteAfter the port number is changed, you cannot use the default port 22 to connect to the instance.