×
  • Shared Hosting

    Fast reliable and affordable cPanel Web Hosting from $2.99 per month.

  • Reseller Hosting

    Multiple websites? No problem with our multi-site hosting package. From $5.99 per month.

  • Annual Hosting

    Save money on web hosting by paying annually. Starting at $29.99 per year.

  • VPS Servers

    Need more power and resources? Choose our VPS server, only $7.99 per month.

  • FREE HOSTING PLAN

    Ideal for students and unemployed.

    Register

How to change Port 22 on CentoS 7

10/01/2019 | |0 comment

I know I’m not the only one who has experienced this security issue.  Particularly after taking occupation of a new VPS.  When I SSH into the VPS it showed a huge number of failed login attempts.  This had me worried.  Apparently this happens to almost every one with a new VPS and two of the most common ways to secure a VPS from these login attempts is to change the port number of the VPS and/or create a keyless entry without password.  I tried both and rejected the keyless entry as found myself locked out of my VPS after the second month of using this method.  However, when I changed my Port 22 to a different number, there were no more failed login attempts.

Before you do this though be cautious, as when I changed my port number my VestaCP panel wouldn’t work any longer.  In the end I had to reload my VestaCP from scratch.  So it’s better to do the port number change right at the beginning of taking occupation of the VPS as a first step.

This is how I created a new random port number for my VPS with CentOS 7:

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

service sshd restart

After the change of the port number I had no more bad login attempts.  This really works well.

Genesis