How Do I Change My Server's Port?

Why should I change my server's port? 

The default SSH port is 22. It is recommend to change these settings as soon as possible on your server, because 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 servers port depends on the Operating System (OS) that your server uses. Below you'll find guides on how to change the port on Windows and Linux servers.

How do I change my port on a Windows server?

  1. Launch the Registry editor by typing in the Windows search box:
  2. The registry editor that has just opened should look like this picture:
    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 official documentation from Microsoft for detailed information, including PowerShell commands.
  10. Once you want to establish a RDC connection to the server using non-standard port it is necessary to specify the port which should be used. This can simply be done by adding a colon and the new port. For example: (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 atleast one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article

Modified on 14 Mar 2024

Can’t find what you’re looking for?

Get in Touch

Do you have a pre-sales question?