- Documentation
Elastic Compute Service
Elastic Compute Service
Best Practices
Security
Changing default ports for logging in to ECS instances remotely
Security
Changing default ports for logging in to ECS instances remotely
Changing default ports for logging in to ECS instances remotely
When you use ECS Terminal or a third-party tool to log in to an instance via remote desktop, a Linux instance defaults to the TCP protocol and port 22, and a Windows instance defaults to the TCP protocol and port 3389.
If you need to change the default remote login ports to reduce the risk of scanning and attacks by malicious software and improve instance security, this topic is for your reference.
warning
After the change, you can no longer access the ECS instance using the original default port.
- If you need to change the port again or reuse the original default port, perform as instructed in this topic again.
- If you cannot remotely log in to the instance after changing the port, log in via VNC tools, and then perform as instructed in this topic for changes.
Procedure
Linux operating system
Windows operating system
CentOS is used as an example.
You can change the default login port only after logging in as the root account.
- Execute the following command to back up the configuration file of the sshd service.
- Execute the following command to modify the sshd_config configuration file.
- Press the i key to enter edit mode. Then, under the #Port 22 line, add a new line with the new port in the format Port [new port number], for example, Port 1122.
-
- Press the Esc key, enter :wq, and then press Enter to save and exit the sshd_config configuration file.
- Execute the following command to restart the sshd service. After the restart, you can log in to the Linux instance via SSH on port 1122.
- This allows TCP requests from any address to connect to the ECS instance on port 1122. You can also specify a source address range to control where requests come from.
- Click "Confirm". If you can log in to the instance, the port is configured successfully.
You can change the default login port only after logging in as the Administrator account.
- Click "Start > Windows Administrative Tools > Registry Editor" to open the registry editor.
- In the left navigation pane, select "HKEY_LOCAL_MACHINE > System > CurrentControlSet > Control > Terminal Server > WinStations > RDP-Tcp".
- Find "PortNumber" in the list on the right, right-click it, and then select "Modify...".
- In the pop-up dialog box, specify "Base" as "Decimal". In the text box under "Value data", enter the new port number for remote login, such as 3300, and then click "OK".
- Select "Start > Windows PowerShell". In the Windows PowerShell window, enter "services.msc" and press Enter to open the Services window.
- In the Services window, find "Remote Desktop Services" and right-click this option. Then, select "Restart" to restart the remote login services.
- This allows TCP requests from any address to connect to the ECS instance on port 3300. You can also specify the range of source addresses to control where requests come from.
- Click "Confirm". If you can log in to the instance, the port is configured successfully.
Last updated: 2026.06.18 17:49:50