Linux Tips: Introduce two ways to modify port 22

  
                  

The first one:


01 If you want to change the default port of SSH (22), then you only need to modify: Port 22 in /etc/ssh/sshd_config, here change 22 to yourself Set the port on the line, but do not set the same port as the existing one, in case of unknown consequences.


02 If you want to limit the IP of SSH login, you can do the following:


First: modify /etc/hosts.deny, add sshd:ALL in it >


Then: Modify: /etc/hosts.allow, set the following settings: sshd: 192.168.0.241


This will limit the IP of only 192.168.0.241 via SSH Log in to the Linux machine. Of course, as a server, I don't have gnome and KDE installed, and many don't install it, which increases the security factor.


Second:


First modify the configuration file

vi /etc/ssh/sshd_config


Found# Port 22, here is the default use of 22 ports, modified as follows:


Port 22

Port 50000

Then save and exit


Execute /etc/init.d/sshd restart

This way the SSH port will work with both 22 and 50000.


Edit the firewall configuration now: vi /etc/sysconfig/iptables


Enable 50000 port.

Execute /etc/init.d/iptables restart


Now use the ssh tool to connect to port 50000 to test if it is successful. If the connection is successful, edit the sshd_config settings again and delete the Port22 inside.


The reason why the two ports are set first, and then the port is closed after the test is successful, in the process of modifying the conf, in case there is an unknown situation such as dropped calls, broken networks, misoperations, etc. At that time, it is also possible to connect to another machine through the connection to avoid the connection, and it is necessary to send someone to the machine room, which makes the problem more complicated and troublesome.

Copyright © Windows knowledge All Rights Reserved