RHEL7 Modifying the SSH default port and modifying the SELinux running state

Source: Internet
Author: User
Tags ssh port

RHEL7 after installation, the SSH service is turned on by default for remote configuration, but the default port 22 is not safe, the default port is generally not recommended, then modify the SSH default port. Modifications on the sshd_config inside are similar to those in the 7.0, but be aware of the changes to the SELinux RHEL7.0.

To modify a step:

1. Check if SSH package is installed # Rpm-qa|grep SSH

2. Check if the service is open # Systemctl status Sshd.service

3. Check the process running status # PS-EF |grep sshd

4. Check the program running port # NETSTAT-ANPL |grep sshd

5. Modify sshd config file # vim/etc/ssh/sshd_config

Remove the # number in front of "#Port 22" and add a new line to port 1522 (customizable port): X Save exit

6. Restart SSH Service # systemctl Restart Sshd.service

7. Open Firewall port:

Add Port # firewall-cmd--zone=public--add-port=1522/tcp--permanent

Reload # Firewall-cmd--reload

Restart Service # Systemctl Restart Firewalld.service

View Port # Firewall-cmd--zone=public--list-all

8. Modify the SELinux port:

Check if SELinux is enabled # sestatus-v |grep selinux

SELinux status:enabled #表示启用

Check if Semanage installs # Rpm-qa |grep Policycoreutils-python

If not installed, please install the Toolkit # Yum Install Policycoreutils-python

View current SELinux allowed ports # semanage port-l |grep SSH

Add New Port # semanage port-a-T ssh_port_t-p TCP 1522

Check whether to add success # Semanage port-l |grep SSH

Restart SSH Service # systemctl Restart Sshd.service

Attention:

SSH port default is 22, if you want to modify the port, you can add a port, the method as above, use the new port to log in and then comment out the 22 port (note also modify the firewall # Firewall-cmd--zone=public--remove-port=22/tcp-- Permanent, then reload # firewall-cmd--reload). If you increase the port number, you need to cancel the # number of Port 22 and add a new port port to the other line.

To delete a deactivated port, use the-d delete command, # semanage port-d-T ssh_port_t-p TCP 1522

RHEL7 Modifying the SSH default port and modifying the SELinux running state

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.