How to Change SSH Port on Ubuntu

ChrisM

Cocktail Enthusiast
Verified Provider
How to Change SSH Port on Ubuntu:

 

To change the SSH port for our Ubuntu server, we
 
Last edited by a moderator:

D. Strout

Resident IPv6 Proponent
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

Just a dude
vpsBoard Founder
Moderator
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.
 

sv01

Slow but sure
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
 

NodeBytes

Dedi Addict
@rsk - That's why I always get my dedis with an ipmi/kvm/drac.
 
Last edited by a moderator:

earl

Active Member
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

New Member
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:

nunim

VPS Junkie
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:

HBAndrei

Active Member
Verified Provider
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.
 

HalfEatenPie

The Irrational One
Retired Staff
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:

mpkossen

New Member
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

The Irrational One
Retired Staff
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. 
 
Top