Modify the ssh service port and the corresponding iptables settings
Source: Internet
Author: User
Note: modifying the SSH Port can greatly prevent hackers from scanning and increase the security factor of the system. Recently, some customers have not set a firewall after modifying the port, resulting in the original port 22, the modified port cannot connect to VPS. Here we will teach you how to modify security and enable the corresponding port in iptables: Implementation: 1. modify the SSH configuration file # vi/etc/ss
Note: Modifying the SSH Port can greatly prevent hackers from scanning and increase the security factor of the system. Recently, some customers have not set a firewall after modifying the port, resulting in the original port 22, the modified port cannot connect to VPS. Here, we will teach you how to modify security and
IptablesOpen the corresponding Port:
Implementation:
1. modify the SSH configuration file # Vi/etc/ssh/sshd_config # Find Port 22, which indicates that Port 22 is used by default and changed
Port 22
Port 1234
#/Etc/init. d/sshd restart
In this way, SSH ports will work on both 22 and 1234.
2. add firewall rules # Iptables-a input-p tcp -- dport 22-j ACCEPT
# Iptables-a input-p tcp -- dport 1234-j ACCEPT
#/Etc/rc. d/init. d/iptables save
#/Etc/rc. d/init. d/iptables restart
Then, use the SSH tool to test whether the port you set can be used normally. If it can be used properly, return to step 1, delete Port port22 in/etc/ssh/sshd_config, and delete port 22 in the firewall.
The reason for first setting two ports and then disabling one after the test is successful is to prevent unknown situations such as disconnection, network disconnection, and misoperation during the modification process, you can also use another port for connection debugging to avoid connection failures.
Appendix:Set preset rules. The INPUT chain is rejected by default, the OUTPUT chain is accepted by default, the FORWARD chain is rejected by default, and common operations # Iptables-F // clear the rules of all rule chains in the filter of the preset table
# Iptables-X // clear the rules in the user-defined chain in the filter of the preset table
# Iptables-P INPUT DROP
# Iptables-P OUTPUT ACCEPT
# Iptables-P FORWARD DROP
# Iptables-L-n -- line # display firewall rules by number of rows
# Iptables-d input 1 # delete the first entry of the INPUT table
# Iptables-a input-s 127.0.0.1-d 127.0.0.1-j ACCEPT # ACCEPT the source and target 127.0.0.1, and put this article at the end.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service