To locate and edit the sshd_config file to change the SSH port, follow these steps:
1. Find the sshd_config file:
Run the command:
find / -name "sshd_config" 2>/dev/null
Example output:
/etc/ssh/sshd_config
2. Edit the file:
Open the sshd_config file using a text editor, such as nano:
nano /etc/ssh/sshd_config
3. Locate the Port option:
Find the line that reads:
Port 22
or
#Port 22
4. Change the port number:
To set the port to 2222 (example), modify the line to:
Port 2222
5. Save and close the file:
Press Ctrl + O to save the changes, then Ctrl + X to exit nano.
6. Restart the SSH service:
Restart the SSH service to apply the new port configuration:
service sshd restart
Please note that when choosing a new port number, it is recommended to use a value between 1024 and 65535, as ports 0-1023 are reserved for system services.