Rate This Document
Findability
Accuracy
Completeness
Readability

Changing the Server Port Number

You are advised not to change the port number unless necessary. Otherwise, permission and configuration problems may occur, resulting in access failures.

  1. Use a remote terminal to log in to the server. The following describes how to change the server port number on Ubuntu 20.04.3.
  2. Run the following command to view and modify the existing port configuration, and then save the file. See the following figure.
    vim /etc/ssh/sshd_config
    • The comment tag (#) in #Port22 is added by default. Set it to a new port number. Ensure that the new port number is unique.
    • The default SSH listening port is 22. If you do not forcibly change it, 22 is used no matter you delete the comment tag (#) or not.
  3. Run the following command to restart the SSH service for the configuration to take effect:
    systemctl restart sshd
  4. Log in to the server locally via SSH to check whether the configured port number takes effect.