How To Change Default SSH Port in Ubuntu? [Linux Tip]

Not everyone has system administrators running around them, to take care that no one hacks their servers and ensure all the updates are up and running. We talked about securing a system by disabling direct root access/login for a Linux based system, but we would like to continue it by helping you know, how you can make your system a bit more secure albeit not completely, by making a simple change.

In this post we will show you, how you can change the default SSH port from the world known 22 to something else.

Note: Having your SSH running on port 22 does not mean that you are running a insecure system, this tip only makes it a bit harder to guess on which port SSH is accessible from.

To change your default SSH port from 22 to something else you will need to have root access (you can read our earlier article on disabling direct root access and claiming it for any user) before you make any of the changes.

Once you have root access open the file /etc/ssh/sshd_config and search for Port, it should show 22 as the default value. Change 22 to any port you want that is not already being used on the system.

change-ssh-port

Once you have made the change to use a different port, save the file and issue the command /etc/init.d/ssh reload. That’s it your default SSH port should be disabled now, you will need to setup your SSH clients to reflect the changes, or else you may see Permission Deniederrors.

While logging in from another server, instead of typing ssh servernametype in ssh p portnumber servername, replace the portnumber with the port number you setup in the earlier steps.

If you are using putty just change the default port from 22 to your new port and save the settings.

  • Share

After Reading This Post Other People Went on to Read: »

Read More On:

Comment Using Facebook

9 Responses to this Article | Share your Opinions/Comments

We moderate comments to prevent spam. Moderation is done within few hours. Please try and stay on topic and refrain from using abusive language. If you think there is a problem with this post, please email the post author or send us an email at tips@techie-buzz.com with the URL and the problem you see and we will rectify it as soon as we can.

  1. Ramesh | The Geek Stuff on July 21st, 2008 at 1:56 am #

    It is /etc/init.d/sshd reload. i.e instead of ssh, it should be sshd – SSH daemon.

    Ramesh
    The Geek Stuff

  2. Keith Dsouza on August 5th, 2008 at 12:05 am #

    @Ramesh In Ubuntu when you install openssh the daemon is installed as ssh instead of sshd, Ubuntu dropped the d form most of the daemon. I am running this on Ubnutu hardy installation.

  3. sean on February 15th, 2009 at 11:40 am #

    This is the second post I’ve seen like this neither work.
    Running Intrepid Ibex…
    Thank goodness there is still fedora core and centOS. apache2 was really hard to install from source and a complete pain in the as* as well.

  4. Mark (fetdigitaal.nl) on April 6th, 2009 at 3:54 pm #

    Oke ik heb werkelijk geen id

  5. scott on February 13th, 2010 at 8:41 pm #

    it worked thanks

  6. lamnah on May 3rd, 2010 at 11:44 pm #
  7. Dean on August 3rd, 2010 at 2:15 pm #

    Worked great for me using 10.04 server edition..

    ssh’d in normally using PutTTy..

    Typed sudo vi /etc/ssh/sshd_config

    Modified “Port” line (near top) from 22 to my port.

    Saved/quit vi

    Typed sudo service ssh restart

    Logged out of ssh and then attempted using standard port and failed. ssh’ed in using new port, and all is working fine.

    Thanks!

  8. John on January 4th, 2011 at 11:43 am #

    Be carefull to change SSH port! Don’t change “Port 22″ line, just add “Port 3333″, after that restart sshd. And then check 3333 port availability (it happens that provider blocks some non-standard incoming ports) at http://check-host.net/check-tcp . After successfull result you could delete “Port 22″ line and restart sshd again.

  9. yet another web development blog on March 12th, 2011 at 6:03 am #

    I made myself an article on how to change default ssh port on ubuntu.