Заметки сисадмина » Ubuntu: Change the SSH Port in the operating system

Заметки сисадмина о интересных вещах из мира IT, инструкции и рецензии. Настраиваем Компьютеры/Сервера/1С/SIP-телефонию в Москве

Ubuntu: Change the SSH Port in the operating system

2024-10-26 · Posted in Ubuntu

To gain privileges in Linux we use two commands:

Update the firewall

Update the firewall to ensure that the system allows incoming connections to the newly specified port. Enter
the following command with your new port:

Edit the SSH daemon configuration file

Perform the following steps to edit the configuration file:

1)Run the following command to open the sshd_config file:

2)Use the arrow keys to scroll through the file until you locate the following text:

3)Move the cursor to the line below the #Port 22 line and press the i key to enter Insert Mode.

4)Press Enter to insert a new line and enter Port <Specified Port Number>. Port 2021 is the new SSH port in the following example:

5)Press the Esc key to exit Insert Mode and enter :wq to save your changes and close the file.

Restart SSH daemon

To restart the SSH daemon and complete the bind to the newly specified port, run the following command:

Verify the bind to the new port

Run the following commmand to verify the bind:

Verify the change by logging in

Attempt to log into the server with Secure Shell (SSH). You should see the following response:

Now, SSH by using the -p <Port Number> option. This should work:

Leave a Reply