I want to run a command automatically after I connect to another machine via ssh, without the ssh session being closed automatically.
After searching the internet I found some solutions but none of them work the way I need.
ssh bla@bla "ls"
This runs the ls
command on the remote machine, shows me the output and closes the connection.
I also tried editing the ssh config file with
Host bla
HostName bla
User bla
IdentityFile ~/.ssh/key
RemoteCommand ls
RequestTTY force
Same issue, this connects via ssh, runs the ls
command, shows me the output and then exits. Not even the RequestTTY
option helped.
ssh bla@bla "ls ; bash"
This doesn't disconnect after running ls
, but I don't get a full terminal interface, just some bare bones command line that doesn't show the me@machine:~$ thing
.
What I actually want:
Either some bash alias, or .ssh/config
entry that will allow me to type in a simple command which will connect to the remote machine and then run a command there and leave the terminal open.
Basically as if I did this by hand:
type
ssh blah@blah
and then after it connects I would type
ls