Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to modify SSH port number information in Linux

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Xiaobian to share with you how to modify SSH port number information in Linux, I hope you have something to gain after reading this article, let's discuss it together!

In linux, the default SSH port number is 22, because this is the port number that everyone knows, once an intruder scans port 22, they immediately know that this is the port number for SSH login, so we need to modify the default port number.

Once vps is in hand, the first thing to do is to change the ssh port, using a port number that is not easy to disassemble, to prevent hacking.

Change the port number is achieved by modifying the SSH configuration file. After logging in to ssh, enter:

vim /etc/ssh/sshd_config

Go down to #Port 22.

Enter vi insert mode for editing

Delete the #in front of Port 22, and then enter the new port number in the next line, such as Port 10000 (this is your own decision, the maximum cannot exceed 65535)

After editing, press ESC and enter:wq to save and exit.

Then restart ssh with the following code:

/etc/init.d/sshd restart

Then log in using port 10000 to see if the connection can be successful. After the connection is successful, delete port 22.

However, there is a problem here. Most linux servers have their own firewall iptables rules. Set port 10000 in the rules for standby release.

iptables -I INPUT -p tcp --dport 10000 -j ACCEPT

Parameter-I is to insert the above rule into the front of the iptables rule, then delete the ssh default port 22, save the rule, restart the firewall, and that's it.

Let's talk about how to delete iptables rules. Sometimes some rules are too long. When deleting them, you have to write a long string. It is both a waste of time and easy to write mistakes. At this time, we can first use-line-number to view the line number of the rule, and then delete it by line number. The code is as follows:

[root@test ~]# iptables -nL --line-numberChain INPUT (policy ACCEPT)num target prot opt source destination1 DROP all -- 192.168.1.1 0.0.0.0/02 DROP all -- 192.168.1.2 0.0.0.0/03 DROP all -- 192.168.1.3 0.0.0.0/0

For example, delete the second rule and enter:

[root@test ~]# iptables -D INPUT 2

After reading this article, I believe you have a certain understanding of "how to modify SSH port number information in Linux". If you want to know more about it, please pay attention to the industry information channel. Thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report