Introduction to the SSH port number change method in Linux

Source: Internet
Author: User
Tags ssh iptables port number ssh port


VPS one hand, the first thing is to change the SSH port, using a not easy to disassemble the port number, to prevent being black.

Changing the port number is done by modifying the SSH configuration file, and after logging in SSH, enter:

Vim/etc/ssh/sshd_config

Down to find #port 22 this section

Enter VI insert mode for editing

Delete the # in front of Port 22, and then enter the new port number on the next line, such as Port 10000 (this is your own set, Max can not exceed 65535)

Edit, press ESC First, then enter: Wq save exit.

Then restart SSH with the following code:

/etc/init.d/sshd restart

Then use the 10000 port login to see if the connection is successful and the connection succeeds in removing the 22 port.

However, there is a problem, the General Linux server has its own firewall iptables rules, the port 10000 in the rule set to release.

Iptables-i input-p TCP--dport 10000-j ACCEPT

Parameter-I inserts the above rule at the top of the iptables rule, and then removes SSH's default 22 port, saves the rule, and restarts the firewall.

Next, how to delete iptables rules, sometimes some rules are too long, delete to write a large string, both waste time and easy to write wrong, then we can use –line-number to view the line number of the rule, and then deleted by line number, the code is as follows:

[Root@test ~]# iptables-nl--line-number
Chain INPUT (Policy ACCEPT)
Num Target prot opt source destination
1 DROP All--192.168.1.1 0.0.0.0/0
2 DROP All--192.168.1.2 0.0.0.0/0
3 DROP All--192.168.1.3 0.0.0.0/0

For example, to delete the second rule, enter:

[Root@test ~]# iptables-d INPUT 2

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.