Run ssh and immediately execute command [duplicate]

I’m trying to find UNIX or bash command to run a command after connecting to an ssh server. For example:

ssh name@ip "tmux list-sessions"

The above code works, it lists the sessions, but it then immediately disconnects. Putting it in the sshrc on the server side works, but I need to be able to type it in client side. I want to be able to run a command, it logs in, opens up the window, then runs the command I’ve set. Ive tried

[command] | ssh name@ip

ssh name@ip [command]

ssh name@ip "[command]"

ssh -t name@ip [command]

3 Answers
3

Leave a Comment