Jtti: How to modify the remote ssh port number in Ubuntu18.04

To modify the remote port number for SSH on Ubuntu 18.04, you need to edit the SSH server configuration file and specify the new port number. Here are the specific steps:

Log in to your Ubuntu server as root or a user with sudo privileges.

Back up SSH configuration files (optional):

Before making any changes, it is recommended to back up the current SSH configuration file. You can create a backup using the following command:

sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config_backup

Open the SSH configuration file using a text editor:

Typically, the SSH configuration file is located at /etc/ssh/sshd_config. You can use your favorite text editor, such as nano or vim, to edit this file:

sudo nano /etc/ssh/sshd_config

If using the nano editor, use the arrow keys to scroll to the bottom of the file.

Find and modify the SSH port settings:

In the configuration file, find the following line, which is the default port setting for SSH:

Port 22

Change the number 22 after Port to your desired new port number. Make sure the new port number is unoccupied and within a reasonable range, such as 1024 to 65535.

save document:

In the nano editor, press Ctrl + O and then Enter to save changes. Then press Ctrl + X to exit the editor.

Restart the SSH service:

Use the following command to restart the SSH service for the changes to take effect:

sudo systemctl restart ssh

Firewall settings (if required):

If you have a firewall enabled, make sure to allow the new SSH port in the firewall rules. For example, if you use a ufw firewall, you can run the following command to allow the new SSH port:

sudo ufw allow new port number/tcp

Then enable the firewall:

sudo ufw enable

Finally, check that the firewall rules are correct:

sudo ufw status

The SSH service will now listen for connections on the new port. Make sure that after making the port change, you can use the new port to connect to the server. If you are using a firewall before connecting remotely, make sure the firewall rules are updated to allow the new port.

Guess you like

Origin blog.csdn.net/JttiSEO/article/details/132624288