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.
Use the default port 22 to connect to the simple application server. For more information, see connect to a Linux server.
Run the following command to back up the
sshd_config
service configuration file.sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config_bak
Modify the sshd configuration file.
Run the following command to modify the
sshd_config
configuration file.sudo vi /etc/ssh/sshd_config
Find the
#Port 22
line in thesshd_config
file and press theI
key to enter edit mode.Enter
Port 24
below#Port 22
to usePort 24
as the custom port in the following example.Press the
Esc
key, enter:wq
, and then press the Enter key to save and close the file.
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.
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.
Modify the value of the PortNumber registry subkey.
Press
Win+R
to open the running dialog box, entercmd
, pressCtrl + Shift + Enter
to log on to the server as an administrator.Enter
regedit
in the command line window.Go to
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp
.Find and right-click PortNumber in the right list, and select Modify...
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.
Queries the name of the RDP service.
Enter
services.msc
on the command line page to open the service interface.On the Services page, right-click Remote Desktop Services and select Properties.
On the Regular page, click your Service Name
TermService
.
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
Log on to the Simple Application Server console.
In the left-side navigation pane, click Servers.
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.
In the Connect dialog box, select Connect with One-click on Workbench or Password-based Logons on Workbench.
Click Modify, enter the custom port number that you set in the field, and then click Confirm to modify.
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.
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.