How to temporarily run a secondary SSH server on a separate port

You didn't mention an Ubuntu version, so I am not sure which init system you are running.

If systemd, you may have a file /etc/systemd/system/sshd.service. Which you could make a copy of as /etc/systemd/system/sshd_alt.service. Then adjust the ExecStart line and add a -p 22000 or something. After that do systemctl enable sshd_alt and systemctl start sshd_alt. You could also point at a completely different configuration file.

You could also just manually start a copy in screen or something if this is just a one time thing. Just start screen and do something like /usr/sbin/sshd -D -p 22200. You will start a spare sshd daemon until you can re-attach to that screen and kill the process.

Or like @EEAA said. Simply don't disconnect, use a second session to test that you can reconnect.


You can start an sshd on an alternate port with this command:

sshd -p 12345

Replace 12345 by your favorite port number. If sshd is not in your PATH, you may need to use the full pathname in the command, e.g. /usr/sbin/sshd.


Just leave one SSH session active and use another to make your configuration changes. Your original session will remain connected and available to revert changes if your config changes break something.