Modify the ssh port and centosssh port of centos
Vi/etc/ssh/sshd_config
Find the section # Port 22, which indicates that Port 22 is used by default, and add a line as follows:
Port 34981
Save and exit
Then the service sshd restart
Note: Do not turn it off here.
In addition, open a new window and try to connect to sshd. If the connection is successful, delete port 22 and restart ssh. If not, use port 22.
In this way, no exception occurs when you reset the ssh port.
How does one change the SSH port in Linux?
Vi/etc/ssh/sshd_config, find Port 22, change Port 22 to the desired Port number, and restart the SSH service:/etc/init. d/sshd restart, and then test the ssh connection: ssh localhost-p your port number. The connection is successful. If you want to avoid using ssh connections because one port cannot be connected (for example, under attack), you can use multiple ssh connection ports, in the configuration file/etc/ssh/sshd_config, run vi/etc/ssh/sshd_config, find the Port, and add a line below: Port 23, in this way, a new connection port is added, the SSH service is restarted, and ssh localhost-p 23 is tested. The connection is successful. In addition, if the local test is normal, but you still cannot use the third-room tool to access the external SSH link, you need to disable the firewall and Restart SSHD. In this way, you can.
How can I change the port used for linux ssh?
Ssh? Do you want to change the server or client?
The command format is as follows:
Ssh-p port # host
If you use a port forward tool like proxy, run the following command:
Ssh-L local_port: remote_host: remote_port hostname
Here
Local_port can be any available local port, generally over 1024
Remote_host is
If the server is changed, the configuration file is modified. Generally, sshd is used. The configuration file is usually in/etc/ssh/sshd_config.
Search for # Port and replace # Port with the Port you want
If iptables has settings, do not forget to open the new port.