Linux Modify SSH default port method detailed

Source: Internet
Author: User
Tags ssh iptables ssh port


First type:
01 If you want to change the Linux SSH default port (22), then you only have to modify:/etc/ssh/sshd_config Port 22, here 22 into their own to set the port on the line, but do not set and now have the same port, in case of unknown consequences.


02 If you want to limit SSH login IP, you can do the following:


First: Modify/etc/hosts.deny, add Sshd:all in it


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


This will limit only 192.168.0.241 of IP access to the Linux machine via SSH. Of course, as a server, I do not install GNOME and KDE, and many things are not installed, so as to increase the safety factor.


The second type:


First 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 50000
And then save the exit


Perform/etc/init.d/sshd restart
This way the SSH port will work concurrently with 22 and 50000.


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


Enable Port 50000.
-A input-m state--state new-m tcp-p TCP--dport 50000-j ACCEPT


Perform/etc/init.d/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 first, test successful and then shut down a port, is in order to modify the process of 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 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.