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