arrow_upward

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to change the port number on CentoS 7
#1
Step 1  Choose a random number between 49152 and 65535

Step 2  SSH into your VPS - if you don't have NANO already loaded with CentoS - you can do it with this command:

yum install nano

Step 3 Use this command to edit the port number

nano /etc/ssh/sshd_config

With nano you'll be able to scroll with your up and down keys to:

#Server 22

Delete # and replace 22 with your random number.  Remember to make a note of the new number.


Step 4 Save the change with 'ctrl o'  and exit with 'ctrl exit'

ctrl exit

Step 5 Change IP tables (replace "newnumber" with your new port number):

iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport newnumber -j ACCEPT

iptables -A INPUT -j DROP -p tcp --dport 22

/etc/init.d/iptables save

If you have a Panel, you also need to go into the Panel and in the case of VestaCP there was a separate setting for Firewall SSH port number - which I changed from 22 to my new number.  I also had other issues with VestaCP which I reported in the last post of this tutorial.  VestaCP is still far from perfect, but I think it could possibly also be because of CentOS 7 (probbly still prefer CentOS 6) -  VestaCP httpd and nginx have error issues that come up when ports are changed over and above the ones that have been covered above that come up with this message - resulting in one can't restart either httpd or nginx and websites of course are down as a result:
Quote:See "systemctl status httpd.service" and "journalctl -xe" for details.

Step 6
service sshd restart


Feedback:  After the change of the port number I had no more bad login attempts.  This really works well.
Terminal
Thank you to Post4VPS and VirMach for my awesome VPS 9!  


Messages In This Thread
How to change the port number on CentoS 7 - by deanhills - 07-01-2018, 01:32 AM
RE: How to change Port 22 on CentoS 7 - by Vuluts - 07-02-2018, 01:50 PM
RE: How to change Port 22 on CentoS 7 - by Rehan - 07-02-2018, 03:03 PM

Possibly Related Threads…
Thread
Author
Replies
Views
Last Post
5,342
04-13-2020, 06:45 AM
Last Post: Mashiro
5,718
12-16-2019, 06:52 AM
Last Post: youssefbasha

person_pin_circle Users browsing this thread: 1 Guest(s)
Sponsors: VirMach - Host4Fun - CubeData - Evolution-Host - HostDare - Hyper Expert - Shadow Hosting - Bladenode - Hostlease - RackNerd - ReadyDedis - Limitless Hosting