How do you run an SSH daemon on a different port other than the standard 22?
I screwed up something with my SSH configuration on a cloud VM, so that now SSH always prompts me for a password. My early attempts to fix this locked me out, forcing me to umount the disk, mount it inside a working VM, and fix the files to a known working state. However, it's still forcing me to enter a password.
I'd like to update my /etc/ssh/sshd_config
and restart the main ssh daemon, which I can test against, while still having another one running, using the old configuration, that I can use to revert the configuration in case the first one locks me out. How would I do this, specifically on Ubuntu?
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 theExecStart
line and add a-p 22000
or something. After that dosystemctl enable sshd_alt
andsystemctl 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:
Replace 12345 by your favorite port number. If
sshd
is not in yourPATH
, 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.