[Solved] Unable to change SSH port?

Having issues with your DietPi installation, or, found a bug? Post it here.
Post Reply
ben61694
Posts: 20
Joined: Tue Oct 30, 2018 2:06 pm

[Solved] Unable to change SSH port?

Post by ben61694 »

I'm trying to change the port for openssh.

I went to sudo nano /etc/ssh/sshd_config
removed the # behind Port 22, changed 22 to my own port, then rebooted the device because running:
sudo service ssh restart
will say:
Failed to restart ssh.service: Unit ssh.service not found.

But when I reboot the device and run netstat -l, my port isn't open and it's still listening to port 22.

I tried removing the packaged ssh software that came with dietpi and did
sudo apt-get install openssh-server
and re-changed the sshd_config
But I'm still unable to get a different port listening. Any ideas how to fix this?

Edit: Apparently I can change ports with dropbear but not openssh, any idea why?
Last edited by ben61694 on Sat Nov 17, 2018 6:54 am, edited 1 time in total.
User avatar
MichaIng
Site Admin
Posts: 2293
Joined: Sat Nov 18, 2017 6:21 pm

Re: Unable to change SSH port?

Post by MichaIng »

ssh.service not found? Did you choose openssh as SSH server before in dietpi software? It should simply install the APT package as well as you now did manually.

Jep by default the lightweight dropbear is pre-installed, which uses way less RAM and disk space, but lacks some features like SFTP and such.

Hmm sshd_config should be right then, or does a subfolder for drop in configs exist, e.g. sshd_config.d/ or similar?

Also did you actively purge the dropbear server beforehand? If both are installed, one would fail to bind to the same port.
Actively switch in dietpi software and run Go install would do all this automatically.
ben61694
Posts: 20
Joined: Tue Oct 30, 2018 2:06 pm

Re: Unable to change SSH port?

Post by ben61694 »

Yeah I didn't realize I had to purge dropbear, I tried purging openssh-server from the pi. I went through dietpi-software to switch from dropbear to openssh but it didn't work. I had to set it to none to uninstall both, then install openssh server for it to work. So I'm guessing I had some files that didn't get cleaned somehow. But it does work now. It's weird, I knew it was being reinstalled because sshd_config would be reset with # Port 22 commented out every time I accessed it after installing
User avatar
MichaIng
Site Admin
Posts: 2293
Joined: Sat Nov 18, 2017 6:21 pm

Re: [Solved] Unable to change SSH port?

Post by MichaIng »

Great that it works now.

Hmm strange that it didn't work directly via dietpi-software. We read an issue with that earlier, but were not able to replicate any issue. Perhaps it also depends somehow on APT cache/packages, if Dropbear is successfully stopped and purged first, before OpenSSH is installed (and service can start), or it is somehow the other way round and OpenSSH install will fail due to port being blocked by Dropbear :?. Will play round with this by times.
Post Reply