Ubuntu ubbantu modifies the default 22 system port to provide server security policy

Time:2020-11-1

Lao Zuo’s notesThere was a“Is Ubuntu or Debian image system the cloud server? Choose according to familiarity“It is mentioned in the article that we recommend Debian or Ubuntu when choosing cloud server system. In recent years, Laozuo is more used to using Ubuntu system, so some netizens have seen my suggestion and used it. In the process of use, in fact, we have mentioned before. It is recommended to replace the original default 22 system port with its own port after the system is installed.

If we use tools like the pagoda panel, we can directly replace it in the panel and modify the security group corresponding to the server. But if we directly use the Linux command to install the environment, how can we change the default port 22 of the server? In this article,lefty Record how to modify the default 22 system port to provide server security policy in Ubuntu Ubuntu.

First, backup system configuration files

cp /etc/ssh/sshd_config /etc/ssh/sshd_config.backup

Here we need to jump to the configuration file of the system, so at the beginning, I still suggest you make a backup, so as to avoid the emergency recovery after the failure.

Second, modify the system configuration file

vi /etc/ssh/sshd_config

Here we can download it locally or edit it using the online VIM tool.

Ubuntu ubbantu modifies the default 22 system port to provide server security policy

We can see the figure above. We can change port 22 to other ports. For example, if we change it to 123412, we can exchange for others.

After we save the file, we need to execute it.

iptables -A INPUT -p tcp –dport 123412 -j ACCEPT

We need to release the corresponding port. And if our server has a security group, we also need to open the port to set the release. Of course, we can change the original 22 port.

Third, restart takes effect

/etc/init.d/sshd restart

Here we restart sshd to take effect. It is slightly different if we are other images, especially CentOS. In this way, we can use the new port to log in to the server.

Link to this article:https://www.laozuo.org/16533.html |Lao Zuo’s notes