RHEL7 modifies the SSH default port and SELinux running status, rhel7selinux

Source: Internet
Author: User
Tags ssh port

RHEL7 modifies the SSH default port and SELinux running status, rhel7selinux

After RHEL7 is installed, the SSH service is enabled by default for remote configuration, but the default port 22 is not safe. Generally, we do not recommend that you use the default port, so you can modify the SSH default port. The modification on RHEL7.0 in sshd_config is similar to the modification below 7.0, but note the modification of SELinux.

Modification steps:

1. Check whether the SSH software package is installed # rpm-qa | grep ssh

2. Check whether the service is enabled # systemctl status sshd. service

3. Check the running status of the Process # ps-ef | grep sshd

4. Check the program running port # netstat-anpl | grep sshd

5. Modify the sshd configuration file # vim/etc/ssh/sshd_config

Cancel the # sign before "# Port 22", add Port 1522 (custom Port) in another line, and save and exit x.

6. restart the SSH service # systemctl restart sshd. service

7. Open the firewall port:

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

Reload # firewall-cmd -- reload

Restart the 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 # indicates enabled

Check whether semanage is installed # rpm-qa | grep policycoreutils-python

If not, install the Toolkit # yum install policycoreutils-python first.

View the ports allowed by selinux # semanage port-l | grep ssh

Add a new port # semanage port-a-t ssh_port_t-p tcp 1522

Check whether it is successfully added # semanage port-l | grep ssh

Restart the SSH service # systemctl restart sshd. service

Note:

The default SSH port is 22. To modify the port, add a port as shown in the preceding figure, use the new port to log on and comment out port 22 (note that the firewall is modified at the same time # firewall-cmd -- zone = public -- remove-port = 22/tcp -- permanent, reload # firewall-cmd -- reload ). To add a port number, cancel the # Number of port 22 and add a port number in another line.

To delete a disabled port, run the-d DELETE command, # semanage port-d-t ssh_port_t-p tcp 1522

 

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.