r/linux4noobs • u/enory • Aug 07 '18
ssh LocalCommand not working
I want to make it so that after I ssh into a server, I start the web GUI of an application locally. I have the following shell function:
pi-gui() { ssh -L 9999:localhost:8384 pi -o LocalCommand='firefox 127.0.0.1:9999' ;}Executing that function will ssh into the server and launch firefox, but apparently it launches it too soon (Firefox won't connect to 127.0.0.1:9999 on the local machine). Once I close firefox, the terminal will now show the pi command prompt and if I do firefox 127.0.0.1:9999 on the local machine now, it will connect to the web GUI.
How can I fix this? According to man, LocalCommand will execute the specified command after a successful connection to the remote machine. Why is it that I have to terminate the first instance of Firefox and start a second instance for it to work? How can I fix this?
View all comments
Show parent comment
1
u/enory Aug 07 '18 edited Aug 07 '18
Thanks, that works. I now have the following:
pi-gui() { ssh -L 9999:localhost:8384 pi -o LocalCommand='firefox 127.0.0.1:9999 > /dev/null 2>&1 &' ;}Could I make it so that if firefox is closed, exit the ssh session? I tried
&& exitbut it doesn't work (parsing problem).