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!


Steps

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! icon smile How to change SSH port on Centos,Ubuntu,Debian 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
 How to change SSH port on Centos,Ubuntu,Debian
Ruchira
View all posts by Ruchira

Last 5 posts by Ruchira

  • gavrilo

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

    • http://www.ruchirablog.com Ruchira

      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!

      • http://vbtechsupport.com/ George

        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 ;)

  • Phearun

    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?

    • http://www.ruchirablog.com Ruchira

      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!

  • Phearun

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

    • http://www.ruchirablog.com Ruchira

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

  • Phearun

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

  • akram

    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 ?

  • http://superiorpics.hotthread.net/ kht

    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 :D

Previous post:

Next post: