The tutorial is currently the safest tutorial, if you are a novice please follow the steps of the tutorial strictly, if there is a certain basis for people can selectively skip certain paragraphs
Modify Port Configuration
Run first
Vim/etc/ssh/sshd_config
Find #port 22 This line and then remove the previous comment, then add another line to Port 1234
Port 1234
Many tutorials are directly modified 22 for other ports, it is best not to do so, in case the modified port can not be used, you will not be able to log on, so first left a posterior
Modify firewall configuration
Modify the Iptables (Linux firewall) file:
Vim/etc/sysconfig/iptables
Add a row
Iptables-a input-m State--state new-m tcp-p TCP--dport 1813-j ACCEPT
Shutting down the firewall
Then shut down the firewall
Service Iptables Stop
Turn off SELinux
Important: turn off SELinux first, many tutorials do not mention this, because SELinux default protection level is very high, if you do not close selinux there will be a lot of problems
Vim/etc/sysconfig/selinux
Change the selinux=enforcing line to selinux=disabled and restart
Test connection
After reboot, run the command:
NETSTAT-TPNL | grep ssh
You'll see two ports open at the same time.
[[email protected] ~]# netstat -tpnl | grep ssh tcp 0 0 0.0.0.0:22 0.0.0.0:* listen 1497/sshd tcp 0 0 0.0.0.0:1234 0.0.0.0:* LISTEN 1497/sshd &nbsP; tcp 0 0 :::22 :::* LISTEN 1497/sshd tcp 0 0 :::1234 :::* listen 1497/ Sshd
Important : Then test whether the new port can be connected through
Modifying the SELinux configuration
If normal, proceed with the following steps: Modify SELinux
Just installed CentOS is no semanage command, so please confirm the existence of semanage command, if not, follow the following tutorial installation
# rpm -qa | grep semanag libsemanage-2.0.43-4.2.el6.x86_64 # which semanage /usr/bin/which: no semanage in (/usr/ Lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin) # yum provides /usr/sbin/semanage policycoreutils-python-2.0.83-19.30.el6.x86_ 64 : selinux policy core python utilities repo : base Matched from: Filename : /usr/sbin/semanage # yum whatprovides /usr/sbin/semanage loaded plugins: fastestmirror, refresh-packagekit, security loading mirror speeds from cached hostfile * base: Mirrors.prometeus.net * epel: mirror.switch.ch * extras: mirrors.prometeus.net * rpmfusion-free-updates: rpmfusion.famillecollet.com * rpmfusion-nonfree-updates: rpmfusion.famillecollet.com * updates: mirrors.prometeus.net policycoreutils-python-2.0.83-19.30.el6.x86_64 : selinux policy core python utilities repo : base matched from: filename : /usr/sbin/semanage # yum -y install policycoreutils-python
When you are finished, use the following command to view the SSH ports currently allowed by SELinux:
Semanage Port-l | grep ssh
Will output
ssh_port_t TCP 22
Add 1234 port to SELinux
Semanage port-a-t ssh_port_t-p TCP 1234
Important: then make sure you add it.
Semanage Port-l | grep ssh
If successful will output
ssh_port_t TCP 1234, 22
Turn on SELinux lower security level
Then go to modify the SELinux policy, reopen it, but we first modified to permissive this security level will not intercept your changes, just prompt warning
Vim/etc/sysconfig/selinux
To modify the security level
Selinux=permissive
Then reboot reboot.
important : Once again, test the remote connection with the new port after reboot.
Turn on SELinux normal security level
Test the connection with the new port after rebooting.
If the test is modified by modifying the selinux=enforcing and then restarting, because there are many changes in the way mentioned earlier, this side will not be affixed to the code
Test remote connection with new port again after reboot
Subsequent cleanup steps
If you can, congratulations, the successful configuration of the new port, and then you can do it yourself to remove the 22 port from the Sshd_config, the 22 port removed from the firewall and so on steps
Linux Modify SSH Port