Can't connect though SSH but can connect to SFTP

Ideally, I want to run my system with zsh shell and wan’t to be able to connect with ssh(more so mosh) and sftp. Ideally, I want to use Android App Terminus to connect via Mosh.

I modified sshd to run on porn 40420 but I can’t connect to SSH or Mosh. I can change over to SFTP though. I opened UFW to port 40420 in sshd.congif as well as my router.

Is there a log or something I can refer to troubleshoot this further?

EDIT: Sorry for this showing in announcements. Didn’t mean to.

You’ll have to be more specific… do you get an error? Does it hang forever / time out?

What is the exact command you used (with user/IP redacted if needed)?

Are you certain you’re connecting to port 40420?

If SFTP works, that implies everything on the server side is fine. The issue is most likely on the client side.

The log is journalctl --no-pager -e -u sshd

It pretty much fails instantly. In terminus, I try to connect to my local static IP on port 40420. It claims connection fails: connection refused.

And here is the log:


Feb 07 11:26:16 Xplorer4x4-CachyOS systemd[1]: Starting OpenSSH Daemon...
Feb 07 11:26:16 Xplorer4x4-CachyOS sshd[1308]: /etc/ssh/sshd_config: line 120: Bad configuration option: Host
Feb 07 11:26:16 Xplorer4x4-CachyOS sshd[1308]: /etc/ssh/sshd_config: line 121: Bad configuration option: ProxyCommand
Feb 07 11:26:16 Xplorer4x4-CachyOS sshd[1308]: /etc/ssh/sshd_config: terminating, 2 bad configuration options
Feb 07 11:26:16 Xplorer4x4-CachyOS systemd[1]: sshd.service: Main process exited, code=exited, status=255/EXCEPTION
Feb 07 11:26:16 Xplorer4x4-CachyOS systemd[1]: sshd.service: Failed with result 'exit-code'.
Feb 07 11:26:16 Xplorer4x4-CachyOS systemd[1]: Failed to start OpenSSH Daemon.
Feb 07 11:26:16 Xplorer4x4-CachyOS systemd[1]: sshd.service: Scheduled restart job, restart counter is at 1.
Feb 07 11:26:16 Xplorer4x4-CachyOS systemd[1]: Starting OpenSSH Daemon...
Feb 07 11:26:16 Xplorer4x4-CachyOS sshd[1364]: /etc/ssh/sshd_config: line 120: Bad configuration option: Host
Feb 07 11:26:16 Xplorer4x4-CachyOS sshd[1364]: /etc/ssh/sshd_config: line 121: Bad configuration option: ProxyCommand
Feb 07 11:26:16 Xplorer4x4-CachyOS sshd[1364]: /etc/ssh/sshd_config: terminating, 2 bad configuration options
Feb 07 11:26:16 Xplorer4x4-CachyOS systemd[1]: sshd.service: Main process exited, code=exited, status=255/EXCEPTION
Feb 07 11:26:16 Xplorer4x4-CachyOS systemd[1]: sshd.service: Failed with result 'exit-code'.
Feb 07 11:26:16 Xplorer4x4-CachyOS systemd[1]: Failed to start OpenSSH Daemon.
Feb 07 11:26:17 Xplorer4x4-CachyOS systemd[1]: sshd.service: Scheduled restart job, restart counter is at 2.
Feb 07 11:26:17 Xplorer4x4-CachyOS systemd[1]: Starting OpenSSH Daemon...
Feb 07 11:26:17 Xplorer4x4-CachyOS sshd[1383]: /etc/ssh/sshd_config: line 120: Bad configuration option: Host
Feb 07 11:26:17 Xplorer4x4-CachyOS sshd[1383]: /etc/ssh/sshd_config: line 121: Bad configuration option: ProxyCommand
Feb 07 11:26:17 Xplorer4x4-CachyOS sshd[1383]: /etc/ssh/sshd_config: terminating, 2 bad configuration options
Feb 07 11:26:17 Xplorer4x4-CachyOS systemd[1]: sshd.service: Main process exited, code=exited, status=255/EXCEPTION
Feb 07 11:26:17 Xplorer4x4-CachyOS systemd[1]: sshd.service: Failed with result 'exit-code'.
Feb 07 11:26:17 Xplorer4x4-CachyOS systemd[1]: Failed to start OpenSSH Daemon.
Feb 07 11:26:17 Xplorer4x4-CachyOS systemd[1]: sshd.service: Scheduled restart job, restart counter is at 3.
Feb 07 11:26:17 Xplorer4x4-CachyOS systemd[1]: Starting OpenSSH Daemon...
Feb 07 11:26:17 Xplorer4x4-CachyOS sshd[1403]: /etc/ssh/sshd_config: line 120: Bad configuration option: Host
Feb 07 11:26:17 Xplorer4x4-CachyOS sshd[1403]: /etc/ssh/sshd_config: line 121: Bad configuration option: ProxyCommand
Feb 07 11:26:17 Xplorer4x4-CachyOS sshd[1403]: /etc/ssh/sshd_config: terminating, 2 bad configuration options
Feb 07 11:26:17 Xplorer4x4-CachyOS systemd[1]: sshd.service: Main process exited, code=exited, status=255/EXCEPTION
Feb 07 11:26:17 Xplorer4x4-CachyOS systemd[1]: sshd.service: Failed with result 'exit-code'.
Feb 07 11:26:17 Xplorer4x4-CachyOS systemd[1]: Failed to start OpenSSH Daemon.
Feb 07 11:26:17 Xplorer4x4-CachyOS systemd[1]: sshd.service: Scheduled restart job, restart counter is at 4.
Feb 07 11:26:17 Xplorer4x4-CachyOS systemd[1]: Starting OpenSSH Daemon...
Feb 07 11:26:17 Xplorer4x4-CachyOS sshd[1430]: /etc/ssh/sshd_config: line 120: Bad configuration option: Host
Feb 07 11:26:17 Xplorer4x4-CachyOS sshd[1430]: /etc/ssh/sshd_config: line 121: Bad configuration option: ProxyCommand
Feb 07 11:26:17 Xplorer4x4-CachyOS sshd[1430]: /etc/ssh/sshd_config: terminating, 2 bad configuration options
Feb 07 11:26:17 Xplorer4x4-CachyOS systemd[1]: sshd.service: Main process exited, code=exited, status=255/EXCEPTION
Feb 07 11:26:17 Xplorer4x4-CachyOS systemd[1]: sshd.service: Failed with result 'exit-code'.
Feb 07 11:26:17 Xplorer4x4-CachyOS systemd[1]: Failed to start OpenSSH Daemon.
Feb 07 11:26:17 Xplorer4x4-CachyOS systemd[1]: sshd.service: Scheduled restart job, restart counter is at 5.
Feb 07 11:26:17 Xplorer4x4-CachyOS systemd[1]: sshd.service: Start request repeated too quickly.
Feb 07 11:26:17 Xplorer4x4-CachyOS systemd[1]: sshd.service: Failed with result 'exit-code'.
Feb 07 11:26:17 Xplorer4x4-CachyOS systemd[1]: Failed to start OpenSSH Daemon.

The log is telling you what is wrong: sshd is failing to start due to errors in your /etc/ssh/sshd_config file.

This tracks with the behavior on the client: It’s saying connection refused because sshd is not running and therefore nothing is listening on port 40420.

The only surprising thing is that you say sftp works. That requires sshd to be running, unless you’ve done something quite unusual.

Anyway, it looks like you tried to put a Host section into your sshd_config. That doesn’t belong there. It belongs in the ssh client config (/etc/ssh/ssh_config or, more typically, ~/.ssh/config), not the server (sshd) config.

After fixing your sshd_config, you’ll need to restart your sshd service:

sudo systemctl restart sshd

You can verify what programs are currently listening for connections on which ports like this:

sudo ss -antp | grep LISTEN

That’s what threw me off. The only 3 things I changed in sshd_config were

Port 40420
and
Host internal-server
ProxyCommand /usr/bin/nc -X 5 -x proxyhost:port %h %p

For testing sake I left the port line but commented out the other 2 lines above and it seems ssh is working! The other 2 lines were from googling a fix. Thanks!