SSH default 22 port modification method under Linux OS

Source: Internet
Author: User
Tags ssh iptables ssh port

1th step: If you want to restrict access to Linux via SSH IP, you can do the following:

First: Modify/etc/hosts.deny, add Sshd:all in it, and note that you can't add the # number.

Then: Modify:/etc/hosts.allow, in which the following settings are made: sshd:

This setting only allows IP to log on to the Linux machine via SSH.

Of course, as a server, do not install the GNOME and KDE graphical interface, you can increase the safety factor.

2nd Step: Modify the configuration file


Find #port 221, here is the identity default use 22 port, modified to the following:

Port 22

Port 999

Remove the front # number.

And then save the exit

In the terminal input command:/etc/init.d/sshd Restart to restart the SSH service.

This way the SSH port will work concurrently with 22 and 999.

Edit firewall configuration now: Vi/etc/sysconfig/iptables

Enable Port 999.

-A rh-firewall-1-input-m state–state new-m tcp-p tcp–dport 999-j ACCEPT

In the terminal input command:/etc/init.d/iptables Restart to restart the firewall's access rules.

Now, use the SSH tool to connect to port 999 to test for success. If the connection succeeds, edit the Sshd_config settings and the port of the firewall again, remove the Port22 from the inside, and then restart the access rules for the SSH service and firewall.

The first two ports are set, the test is successful and then a port is closed. is to prevent in the process of modifying the Conf, in the event of a drop in the line, broken nets, misoperation and other unknown circumstances, but also through another port connection up to debug, so as to avoid the connection must send people to the room, causing problems more complex trouble.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.