To change the SSH port on a Linux or Unix server, follow these steps:
- Open the SSH daemon configuration file: The SSH daemon configuration file is usually located at
/etc/ssh/sshd_config
. - Find the line that specifies the
Port
: Look for the line that starts withPort
and change the default port number (22) to the desired port number. - Save and close the file: After making the changes, save the file and close it.
- 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
- 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.