1. Edit Firewall configuration: Vi /etc/sysconfig/iptables Firewall Add New port 7022-a input -m state --state new -m tcp -p tcp --dport 7022 -j accept================================= =====================================# firewall configuration written by system-config-firewall# manual customization of this file is not recommended.*filter:input accept [0:0]:forward accept [0:0]:output accept [0:0]- A input -m state --state established,related -j accept-a input -p icmp -j ACCEPT-A INPUT -i lo -j ACCEPT-A INPUT -m state --state new -m tcp -p tcp --dport 22 -j accept-a input -m state --state new -m tcp -p tcp --dport 7022 - J accept-a input -j reject --reject-with icmp-host-prohibited-a forward -j reject -- Reject-with icmp-host-prohibitedcommit Restart the firewall for the configuration to take effect:/etc/init.d/iptables restartservice iptables restart=======================================================================2, backing up the SSH port configuration file cp /etc/ Ssh/ssh_config /etc/ssh/ssh_configbakcp /etc/ssh/sshd_config /etc/ssh/sshd_ Configbak Modify the SSH port to: 7022vi /etc/ssh/sshd_config add port 7022vi /etc/ssh/ssh_ under Port #port 22 Config adds port 7022 Restart under Port #port 22:/etc/init.d/sshd restartservice sshd Restart with 7022 port can be connected normally, then return to repeat the above steps. The 22 port is disabled, and then SSH can only be connected with 7022 Port! Enhance the security of the system. =======================================================================3, disable root login via SSH vi /etc/ssh/sshd_ Config find Permitrootlogin, change the following yes to No, the previous comment # is canceled, so root cannot telnet! You can log in with a regular account and use the command su root to switch to the root account when using root ========================================================= ==============4, restricting the user's SSH access suppose we just root,User1 and User2 users can use the system via SSH to add vi /etc/ssh/sshd_configallowusers rootuser1user2========= to the Sshd_config configuration file ==============================================================5, configuring idle timeout interval The user can log on to the server via SSH, and you can set an idle time-out interval. Open the Sshd_config configuration file, set as follows. Vi /etc/ssh/sshd_configclientaliveinterval 600clientalivecountmax 0 The above example sets an idle time-out interval of 600 seconds, or 10 minutes, After this time, the idle user will be kicked out automatically (can be understood as exit login/Logoff). =======================================================================6, limit only one IP to telnet to the server vi /etc/ hosts.deny #在其中加入sshd:allvi /etc/hosts.allow #在其中进行如下设置: sshd:192.168.1.1 # ( Allow only 192.168.1.1 this IP telnet server) and finally restart the SSH service:/etc/init.d/sshd restart
This article is from the "-it commune" blog, please be sure to keep this source http://guangpu.blog.51cto.com/3002132/1547913
Linux modifies the default remote connection port