Centos remote SSH port 22 is changed to another port by default

Source: Internet
Author: User
Tags ssh access ssh port

Centos remote SSH port 22 is changed to another port by default

Modify the default SSH port:

1. The file controlling the SSH access port is/etc/ssh/sshd_config.

Therefore, edit the SSH configuration file sshd_config:

# Vi/etc/ssh/sshd_config

2. Find the Port = 22 field and remove the comment above it:

13# Port 22 // remove the annotator #

14 # AddressFamily any

15 # ListenAddress 0.0.0.0

16 # ListenAddress ::

3. Add the same line under this line and change the port number to the one you want to modify:

13 Port 22

14Port 2022 // Add a new row and add the modified Port number

15 # AddressFamily any

16 # ListenAddress 0.0.0.0

17 # ListenAddress ::

4. After saving the modification, restart the SSH service:

#/Etc/init. d/sshd restart // or

# Service sshd restart

5. If no access is available, disable the Firewall:

#/Etc/init. d/iptablesstop // or

# Service iptables stop

Alternatively, add a filter rule to allow access to the newly added port 2022:

# Vi/etc/sysconfig/iptables

Add a policy to allow port 2022:

: Input accept [0: 0]

: Forward accept [0: 0]

: Output accept [0: 0]

-A input-m state -- state ESTABLISHED, RELATED-j ACCEPT

-A input-p icmp-j ACCEPT

-A input-I lo-j ACCEPT

-A input-m state -- state NEW-m tcp-p tcp -- dport 22-j ACCEPT

-A input-m state -- state NEW-m tcp-p tcp -- dport 2022-j ACCEPT

-A input-j REJECT -- reject-with icmp-host-prohibited

-A forward-j REJECT -- reject-with icmp-host-prohibited

COMMIT

6. In this way, you can remotely access the linux host through 2022.

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.