Atlantic.Net Blog

How to Change the SSH Port in CentOS

Jason Mazzota
by Atlantic.Net (29posts) under VPS Hosting
Verified and Tested 4/21/15


In this how-to we will be showing you how to change your SSH port in CentOS. For the exact operating system, we created a brand new CentOS 6.5 64 bit Cloud server. We will be using the vi editor for our file editing needs. Feel free to download and use any editor that you feel comfortable with.

Believe it or not, one of the simplest things you can do to secure your server is to change the SSH port. Since SSH comes on a default port of 22, you will see a lot of brute force attacks occurring over that port because a lot of users do not change this default SSH port!


A server installed with CentOS 6.5 x86_64.  If you currently do not have a server, please consider VPS Hosting from Atlantic.Net.

Changing your SSH port in CentOS

The first thing we want to do is SSH into our server using your preferred SSH client. Be sure that if you are using a custom user, that you have sudo rights. In this step we will be performing commands as the root user.

Log into Root shell

Root Shell

Once you have logged into the server, let’s open our SSH configuration.

vi /etc/ssh/sshd_config

Now once you are in the configuration you’ll want to look for the section that has “Port” in it. It should be near the top and should be shown as “#Port 22.”

Edit "Port" directive in sshd_config

Sample sshd_config

What we will be doing is removing the ‘#’ so that it is a plain line of “Port 22”. Next we will be changing the 22 in the line to be any number you’d like that another program does not run on. For a list of common ports in use, you can check the following MIT page. In our example, we will be changing the SSH port to 922 so your new line should read:

Port 922

Once you have the change done, simply exit and save the sshd_conf file. Now all you need to run is the below command and it will restart the SSH server. The next time you want to connect via SSH, you will need to do so on your new port, in our case, 922.

service sshd restart

Don’t forget to change the port 22 to your new port in your IPTables when done! You can check out the Locking down your CentOS server with IPTables section (link) for information on how to do that.

Note: *If using Cloud services, You can always access your server via our VNC viewer in the Cloud Portal if you lock yourself out*

Get A Free To Use Cloud VPS

Free Tier Includes:
G2.1GB Cloud VPS Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year

Looking for a Hosting Solution?

We Provide Cloud, Dedicated, & Colocation.

  • Seven Global Data Center Locations.
  • Flexible Private, Public, & Hybrid Hosting.
  • 24x7x365 Security, Support, & Monitoring.
Contact Us Now! Med Tech Award FTC
SOC Audit HIPAA Audit HITECH Audit

Recent Posts

Get started with 12 months of free cloud VPS hosting

Free Tier includes:
G2.1GB Cloud VPS Server Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year

New York, NY

100 Delawanna Ave, Suite 1

Clifton, NJ 07014

United States

San Francisco, CA

2820 Northwestern Pkwy,

Santa Clara, CA 95051

United States

Dallas, TX

2323 Bryan Street,

Dallas, Texas 75201

United States

Ashburn, VA

1807 Michael Faraday Ct,

Reston, VA 20190

United States

Orlando, FL

440 W Kennedy Blvd, Suite 3

Orlando, FL 32810

United States

Toronto, Canada

20 Pullman Ct, Scarborough,

Ontario M1X 1E4


London, UK

14 Liverpool Road, Slough,

Berkshire SL1 4QZ

United Kingdom