When connecting to my development server via ssh, I can forward remote ports to local ports via:

ssh my-user@some-domain.com -L 5432:localhost:5432

However I'd rather use mosh because my connection tends to drop.

So I tried extending my usual mosh command (that works) with the --ssh parameter:

mosh --ssh "ssh -L 5432:localhost:5432" my-user@some-domain.com

Which gets me connected without error - but doesn't do anything for my ports.

Is there a way to make port forwarding work when connecting via mosh?


I found an open issue for this exact feature at Mosh's GitHub. And an open bounty at bountysource currently at $616.

So it looks like it's not possible yet.


As a workaround for my SSH disconnect issue I added the following lines to my server's /etc/ssh/sshd_config:

ClientAliveInterval 60  # send null packet every x seconds to clients
ClientAliveCountMax 720  # time them out after doing so y times

Followed by a restart of the SSH daemon and a re-login via SSH.

sudo /etc/init.d/ssh restart
sudo service ssh restart
sudo systemctl restart ssh

This of course doesn't help with situations like changing cell towers on mobile connections like mosh does.

| improve this answer | |

Mosh opens an ssh session to setup the initial connection. Keeping that open would be a good way to maintain port forwarding while still using mosh for interaction. I've tried setting this up without any success

mosh --ssh="ssh -fN" # hangs forever mosh --ssh="ssh -f" # ssh gets terminate

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.