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