Run Remote ssh command with Full Login Shell


I would like to do something like ssh 'ls' However per ssh manpage:

If command is specified, it is
executed on the remote host instead of
a login shell.

So what happens is that ls displays its output and then ssh exits.

What I can't figure out is how to have the full login shell open and then have the command run inside that shell. Leaving the shell open after the command is run. As if I had manually done the following:

  localhost$ ssh$ ls
             /folder2$ _

Any ideas?

Best Answer

Just tell bash to execute ls and then itself in a login shell

$ ssh user@host  -t 'bash -l -c "ls;bash"'