I'd like to run some startup command after login via mosh. With ssh, I'd do it as:

ssh server -t 'some startup command'

But, when I'm doing similar in mosh, I'm getting:

$ mosh elisa2 --ssh="ssh -t 'cat blah'"        
Pseudo-terminal will not be allocated because stdin is not a terminal.
/usr/bin/mosh: Could not resolve hostname cat
ssh_exchange_identification: Connection closed by remote host
/usr/bin/mosh: Did not find remote IP address (is SSH ProxyCommand disabled?).

How to achieve in mosh the similar behavior as in ssh?

2 Answers 2


This is most not possible this way, because the MOSH itself is already running some command to start its process on the remote server. Also the way you wrote it, it is interpreted as a server name, which is certainly not correct.

As reading through the manual page of mosh(1) (good way to start searching next time), you can specify the command simply as the next argument:

mosh [options] [--] [user@]host [command...]


$ mosh elisa2 'cat blah'

should just to the job (you don't need to care about tty in MOSH).

Generally, you want to run also the shell, so after the cat, there should be bash too so you will get the prompt:

$ mosh elisa2 "cat blah;bash"
  • It didn't work for me with the quotes with did without.
    – Kevin
    Aug 16, 2019 at 18:49
  • but did without*. I also noticed that it doesn't work with flags (e.g. htop -t) no matter what I try.
    – Kevin
    Aug 21, 2019 at 6:58

mosh elisa2 -- cat blah

Use the -- to prevent mosh from attempting to parse the command as option flags. It will then pass anything after that through as a command to run on login.

The above command, though, does not start an interactive session. The command will run and then mosh will exit.

To attach to your terminal emulator like you normally would with SSH:

ssh user@host -t 'tmux attach || tmux new'
mosh user@host -- 'tmux attach || tmux new'

ssh user@host -t 'screen -R'
mosh user@host -- 'screen -R'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .