Change SSH Port in Ubuntu 22.04 and CentOS 7

Change the SSH port ( default Port ) in ubuntu, CentOS Linux Server:

Changing the SSH port number is a good idea. because many attackers scan the internet for port 22. If they get any reply they will try to log in to the server with Random Password. So Changing the SSH port may help to reduce the risk. So now in this short tutorial, we will learn  “how to change the SSH port number in Ubuntu or CentOS machines “

open the ssh configuration file.

vim /etc/ssh/sshd_config

Then find the parameter port and change it to desired port number.

Then save the file and exit from the editor. Look at the following image for more details.


Now go ahead and restart the SSH service using the following command.

/etc/init.d/ssh restart

Related Posts:

Testing :

We just changed the SSH default from port 22 to port 29999. Now we will try to connect to that port using the SSH from the remote client.

Now enter the password to login into the server.

That’s it, You successfully changed your SSH port number on your Linux Box.


Hi Guys, I am Venkatesh. I am a programmer and an Open Source enthusiast. I write about programming and technology on this blog.

You may also like...

Leave a Reply