# How to Change SSH Port on Ubuntu



## ChrisM (Jun 12, 2013)

How to Change SSH Port on Ubuntu:

 

To change the SSH port for our Ubuntu server, we


----------



## D. Strout (Jun 12, 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.


----------



## MannDude (Jun 13, 2013)

D. Strout said:


> 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.


Same here. I just connect twice via terminator and make sure I don't fudge stuff up.


----------



## NodeBytes (Jun 13, 2013)

If you do royally fudge up, there's always the console.


----------



## rsk (Jun 13, 2013)

bcarlsonmedia said:


> If you do royally fudge up, there's always the console.


What if it is a dedi and you have no kvm? 

Then it gets to be a hassle...


----------



## sv01 (Jun 13, 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


```
port 8190
```


----------



## NodeBytes (Jun 13, 2013)

@rsk - That's why I always get my dedis with an ipmi/kvm/drac.


----------



## earl (Jun 13, 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.


----------



## 365Networks (Jul 16, 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.


----------



## nunim (Jul 16, 2013)

Or on Debian/Ubuntu (OpenSSH), simply change xxx to your desired port number.


```
sed -i.bak '/Port/c\Port xxx' /etc/ssh/sshd_config
/etc/init.d/ssh restart
```


----------



## Gigi (Feb 3, 2016)

Where is the tutorial?


----------



## Jonathan (Feb 3, 2016)

Uhh @KnownHost-ChrisM there's nothing here


----------



## ChrisM (Feb 3, 2016)

KnownHost-Jonathan said:


> Uhh @KnownHost-ChrisM there's nothing here



@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.


----------



## HBAndrei (Feb 4, 2016)

The extremely simple way would be to run this in cmd:


```
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.


----------



## HalfEatenPie (Feb 4, 2016)

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.


----------



## mpkossen (Feb 4, 2016)

HalfEatenPie said:


> 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.



Switch to WBB ;-)


----------



## HalfEatenPie (Feb 4, 2016)

mpkossen said:


> Switch to WBB ;-)



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.


----------

