How to change SSH port on Centos,Ubuntu,Debian

by Ruchira on January 11, 2011

Keeping the default 22 SSH port is really a very bad practice. I have seen many people doesnt bother changing their SSH port even they configure many security features.

In this short and sweet guide Im going to tell you how to change your SSH port to another. This guide applies for Ubuntu/Debian/Centos/Redhat O/S

Attention- Messing with others things on SSH config file is really dangerous and it may lock your server from accessing via SSH. So you will need console access to reset SSH or contact server provider to do this. So forward with your own risk!


Use NANO editor for edit files. If you dont have NANO installed you can install it by

apt-get install nano or yum install nano

1.You need to open SSHD config file using nano.

nano /etc/ssh/sshd_config

2.Thats your SSHD config file. On that there will be line called

Port 22

We need to change that. You can change the number 22 to whatever port that you like. after you done hit Ctrl+O key on keyboard to write the chnages in to the file and then Ctrl+X to exit the text editor.

3. Restart SSH daemon to apply changes in running configuration

on centos run

service sshd restart

On debian or Ubuntu run

restart ssh

Then you will be immediately logged out from current SSH session because port changed.

Its done! 🙂 Now you can login with your changed port!

Disclaimer- I’m not responsible if you locked your server by changing SSH config file. If you accidentally locked out contact your server company they can fix that for you!

I'm Ruchira Sahan and all posts on this blog are completely my thoughts and writings. I love DIY and Technology. So feel free to contact me for anything about this blog and don't forget to add a comment if this blog helped you! Thanks
View all posts by Ruchira

{ 10 comments… read them below or add one }

1 gavrilo January 11, 2011 at 8:09 AM

why is it a bad practice to leave port 22 as the ssh port ?


2 Ruchira January 11, 2011 at 8:13 AM

Its very bad idea because hackers first try using 22 as port. And all sorts of port scanners used by hackers guess port 22 by default. Its very bad idea to leave 22 as SSH port!


3 George August 17, 2011 at 10:32 AM

Might want to add a note for folks who have a firewall in place i.e. iptables, csf etc to allow the changed port number through 😉


4 Phearun January 20, 2011 at 6:24 AM

Dear, Sir
Can you tell me How to unlock Huawei g2101?
On this I don’t know how to hack it? I can’t use this Phone.
IME:354093041524023 can give me about software to unlock it?
And I have one more can not unlock!
A 3G Wireless Modem, HSDPA,UNTS,EDGE,GPRS. On this modem I don’t have software to unlock.
How can I get the software to unlock it?


5 Ruchira January 20, 2011 at 9:27 PM

sorry I cant help you with phones but there are methods. Whats the model of your HSPA modem? If its huawei you can follow this guide!


6 Phearun January 21, 2011 at 3:53 AM

Thanks.On my modem i can not on the model and about IME: 000000000000000, I never see before, how can I unlock?


7 Ruchira January 21, 2011 at 5:16 AM

YTou can check your imei number with dc-unlocker software! Unlocking is impossible without imei number!


8 Phearun January 21, 2011 at 5:53 AM

Thanks, I used it already but can not .
I don’t know why?
can tell me to use by comment?


9 akram May 7, 2012 at 2:59 AM

Thanks for the tutorial i used all the command but its still open from new port and not open from new port
How to uncomment the port please ?


10 kht June 12, 2012 at 1:04 AM

I’ve tried on debian and use this command to restart ssh

service ssh restart

please note i’m not using “sshd” on command, and its work for me 😀


Leave a Comment

Previous post:

Next post: