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?

  1. Start the Registry Editor by typing the following in the Windows Search box:
    regedit
  2. The registry editor you just opened should look like this:
    windows registry
    windows registry
  3. Navigate to the following registry subkey: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp
  4. Find PortNumber entry.
  5. Click Edit > Modify, and then click Decimal.
  6. Type the new port number, and then click OK.
  7. Close the registry editor and restart your computer.
  8. 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
    set your new port in firewall
  9. Follow the official documentation from Microsoft for detailed information, including PowerShell commands.
  10. 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?

  1. 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.
  2. Connect to your Contabo server.
  3. 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
  4. Find the line containing Port 22.
  5. 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.
  6. Save and exit the sshd_config file (type command “:wq” in the vi editor).
  7. Restart the SSH service using:
    systemctl restart ssh
  8. 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

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article

Modified on Thu, 29 Aug at 3:07 PM

Can’t find what you’re looking for?

Get in Touch

Do you have a pre-sales question?