How Do I Change My Server's Port?
Why should I change my server's port?
The default SSH port is 22. It is recommended that you change this setting on your server as soon as possible, as the default port makes you vulnerable to primitive brute force attacks. By default, there are no restrictions on which port you can use.
The way to change your server's port depends on the Operating System (OS) your server uses. Below you'll find instructions on how to change the port on Windows and Linux servers.
How do I change my port on a Windows server?
- Start the Registry Editor by typing the following in the Windows Search box:
regedit
- The registry editor you just opened should look like this:
- Navigate to the following registry subkey: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp
- Find PortNumber entry.
- Click Edit > Modify, and then click Decimal.
- Type the new port number, and then click OK.
- Close the registry editor and restart your computer.
- Important: Don’t forget to allow the new port in your Windows Firewall. To access the port settings, open your firewall settings and go to: Inbounds rules > New Rule > Port
- Follow the official documentation from Microsoft for detailed information, including PowerShell commands.
- If you want to establish an RDC connection to the server using a non-standard port, you must specify the port to use. This can be done by simply adding a colon and the new port. For example:
73.xxx.xxx.xxx:4567 (To connect to Port 4567).
How do I change my port on a Linux server?
- To grant you all the necessary admin rights, always enter the command sudo -i at the beginning of every session:
sudo -i
This command will grant you the rights of a power user, so you don’t have to write the command sudo at the beginning of every command line. - Connect to your Contabo server.
- Now you have to access and edit sshd_config file. Let’s use the vi text editor in this case:
vi /etc/ssh/sshd_config
- Find the line containing Port 22.
- Replace the number with any value from 1024 to 65536 (command “I” in the vi editor). If there is a hashtag symbol next to “Port”, erase it.
- Save and exit the sshd_config file (type command “:wq” in the vi editor).
- Restart the SSH service using:
systemctl restart ssh
- Don’t forget to adjust your firewall depending on your Linux version. For instance, in case you use Debian or Ubuntu with a default UFW firewall, type:
ufw allow <PORT_NUMBER>/tcp
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article