How to Change SSH Port on Ubuntu

Discussion in 'Tutorials and Guides' started by ChrisM, Jun 12, 2013.

  1. ChrisM

    ChrisM Cocktail Enthusiast Moderator Verified Provider

    688
    281
    Apr 2, 2013
    How to Change SSH Port on Ubuntu:

     

    To change the SSH port for our Ubuntu server, we
     
    Last edited by a moderator: Jun 12, 2013
  2. D. Strout

    D. Strout Resident IPv6 Proponent

    1,180
    364
    Apr 17, 2013
    Good tutorial. Whenever I make any changes to SSH settings over SSH, after restarting the service I leave the current SSH session open and try opening another one with the new settings. If it fails, I've still got a connection to be able to fix things.
     
    mpkossen likes this.
  3. MannDude

    MannDude Just a dude vpsBoard Founder Moderator

    5,036
    2,631
    Mar 8, 2013
    MannDude
    Same here. I just connect twice via terminator and make sure I don't fudge stuff up.
     
  4. NodeBytes

    NodeBytes Dedi Addict

    687
    92
    May 15, 2013
    If you do royally fudge up, there's always the console. :)
     
  5. rsk

    rsk New Member Verified Provider

    173
    27
    May 18, 2013
    What if it is a dedi and you have no kvm? :p

    Then it gets to be a hassle...
     
  6. sv01

    sv01 Slow but sure

    426
    87
    May 17, 2013
    If you need to open more port (for backup if someday your ISP/cyber cafe/Wifi etc block port) add another

    Port [port number here]

    example

    Code:
    port 8190
     
  7. NodeBytes

    NodeBytes Dedi Addict

    687
    92
    May 15, 2013
    @rsk - That's why I always get my dedis with an ipmi/kvm/drac.
     
    Last edited by a moderator: Jun 13, 2013
  8. earl

    earl Active Member

    277
    39
    May 22, 2013
    In centos most times iptables is enabled by default so make sure you add an entry for the new port number in /etc/sysconfig/iptables so you don't lock yourself out.
     
  9. 365Networks

    365Networks New Member

    121
    38
    May 15, 2013
    To do this for dropbear is quite simple, on Debian/Ubuntu based systems:

    Head to /etc/default/dropbear:

    You may have a quite a few lines or you may have little, this just depends on how it was installed.


    # disabled because OpenSSH is installed
    # change to NO_START=0 to enable Dropbear
    NO_START=0

    # the TCP port that Dropbear listens on
    DROPBEAR_PORT=51096

    # any additional arguments for Dropbear
    DROPBEAR_EXTRA_ARGS=-g


    As seen above, you will want to have DROPBEAR_PORT=51096 on a line to change the default dropbear port.
     
    To disable root password login, root logins, etc. you will need to have DROPBEAR_EXTRA_ARGS=xxxxx on another line.
     
    -g = Disable password logins for root
    -s = Disable password logins
    -w = Disable root logins
    An example would be DROPBEAR_EXTRA_ARGS=-s to disable password logins on all accounts including root.

    Finally you will want to service dropbear restart or /etc/init.d/dropbear restart to finalize the changes.

    This is taken from my other post. Just thought it would help some others. :)
     
    Last edited by a moderator: Jul 17, 2013
  10. nunim

    nunim VPS Junkie

    485
    157
    May 15, 2013
    Or on Debian/Ubuntu (OpenSSH), simply change xxx to your desired port number.

    Code:
    sed -i.bak '/Port/c\Port xxx' /etc/ssh/sshd_config
    /etc/init.d/ssh restart
    
     
    Last edited by a moderator: Jul 16, 2013
  11. Gigi

    Gigi New Member

    1
    0
    Feb 3, 2016
    Where is the tutorial? 
     
  12. Jonathan

    Jonathan Woohoo Administrator Verified Provider

    388
    196
    May 27, 2013
    jonspw
    Last edited: Apr 30, 2017
    ChrisM and RLT like this.
  13. ChrisM

    ChrisM Cocktail Enthusiast Moderator Verified Provider

    688
    281
    Apr 2, 2013
    @MannDude vpsBoard broke my thread sometime in the last few years... lol


    Most likely was outdated anyway. I will add fixing this to my to-do list along with make some new tutorials might get some up tomorrow. :)
     
    Last edited by a moderator: Apr 30, 2017
  14. HBAndrei

    HBAndrei Active Member Verified Provider

    160
    59
    May 1, 2014
    The extremely simple way would be to run this in cmd:

    Code:
    sed -i 's/22/48652/' /etc/ssh/sshd_config
    service ssh restart
    Replace 48652 with whatever port you want SSH to run on.


    And make sure the new port is opened in your firewall so you don't get locked out.


    Also, don't close previous SSH session before you open a new one on the new port to make sure everything's working fine.
     
  15. HalfEatenPie

    HalfEatenPie The Irrational One Retired Staff

    2,890
    1,386
    Mar 25, 2013
    HalfEatenPie
    Yeah.  Lovely IPB and the transition between 3.X and 4.X resulted in some threads having data loss.  We thought we got it all by some workaround and fixes we did, however in the end I guess this one slipped through the cracks. 


    tldr: edit /etc/ssh/sshd_config file.  The line that ssays "Port 22" change to "Port 48652" or something.  Then restart the service. 
     
    Last edited by a moderator: Feb 4, 2016
  16. mpkossen

    mpkossen New Member

    91
    65
    May 28, 2013
    Switch to WBB ;-)
     
  17. HalfEatenPie

    HalfEatenPie The Irrational One Retired Staff

    2,890
    1,386
    Mar 25, 2013
    HalfEatenPie
    Man I haven't heard and used Woltlab Burning Board in a long time.  Man that used to be a pretty spiffy forum software.  Although iirc it used to be fairly clunky.


    Right now I"m a fan of Xenforo, but we'll see.