Linux modify SSH port and iptables firewall configuration

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

Linux Modify SSH Port 22

The code is as follows Copy Code

Vi/etc/ssh/ssh_config
Vi/etc/ssh/sshd_config

Then change to port 8888

As Root service sshd restart (Redhat AS3)

Using putty, Port 8888

Linux under the default SSH port is 22, for security reasons, now modify the SSH port is 1433, modify the method as follows:

The code is as follows Copy Code

/usr/sbin/sshd-p 1433

First modify the configuration file

The code is as follows Copy Code

Vi/etc/ssh/sshd_config

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

The code is as follows Copy Code

Port 22
Port 50000

And then save the exit

Perform/etc/init.d/sshd restart

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

Modify iptables configuration file: Vi/etc/sysconfig/iptables Add the following:

The code is as follows Copy Code

-A rh-firewall-1-input-m state--state new-m tcp-p TCP--dport 80-j ACCEPT
-A rh-firewall-1-input-m state--state new-m tcp-p TCP--dport 22-j ACCEPT
-A rh-firewall-1-input-m state--state new-m tcp-p TCP--dport 50000-j ACCEPT

Restart the Iptalbes service:

The code is as follows Copy Code

Service Iptables Restart


Now, use the SSH tool to connect to port 50000 to test for success.
If the connection succeeds, edit the Sshd_config settings again and delete the Port22 inside.

Set to two ports, the test is successful and then close a port, is the way in the process of modifying the Conf,
In the event of a drop, disconnection, misoperation and other unknown circumstances, but also through another port connection up debugging
In order to avoid the connection must send someone to the computer room, causing problems more complicated trouble.

Of course, you can also directly turn off the firewall (not recommended):
Effective after reboot

The code is as follows Copy Code
Open: Chkconfig iptables on
Close: Chkconfig iptables off

Immediate effect, reboot disabled

The code is as follows Copy Code
Open: Service iptables start
OFF: Service iptables stop

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.