When you want to change the default SSH port, you need to edit the SSH configuration file and then restart the SSH service.
First, open the SSH configuration file /etc/ssh/sshd_config with your favorite editor. For example:
sudo nano /etc/ssh/sshd_config
Find the line #Port 22 and change it to your desired port number. For example, to change the port to 2222, you would change the line to:
Port 2222
After saving the file, you need to restart the SSH service for the changes to take effect. On modern Linux distributions that use systemd, you can use the following commands:
sudo systemctl daemon-reload
sudo systemctl restart ssh.socket
This will apply the new SSH port configuration.