SSH default 22 port modification method under Linux OS

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

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:192.168.1.16

This setting only allows 192.168.1.16 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

Vi/etc/ssh/sshd_config

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.

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.