How to change the ssh port on Linux or Unix server

To change the SSH port on a Linux or Unix server, follow these steps:

  1. Open the SSH daemon configuration file: The SSH daemon configuration file is usually located at /etc/ssh/sshd_config.
  2. Find the line that specifies the Port: Look for the line that starts with Port and change the default port number (22) to the desired port number.
  3. Save and close the file: After making the changes, save the file and close it.
  4. Restart the SSH daemon: Restart the SSH daemon to apply the changes. On most systems, this can be done with the following command:
sudo service ssh restart
  1. Verify the changes: To verify the changes, try to connect to the new port using the ssh command. For example:
ssh user@hostname -p new-port-number

After following these steps, the SSH daemon should listen on the new port number, and you should be able to connect to the server using the new port.

Note: Changing the SSH port can help increase security by reducing the attack surface of your server. However, it’s important to remember to update any firewalls and other security-related configurations to allow incoming connections to the new port.

Leave a Comment