I've set up port forwarding over ssh so I can securely connect to a web console. Since the bash command is pretty long, I want to create a small script that will do the following;
- Check if there is an open ssh connection to the server in question.
- If it's not open, open it.
- Open browser to the console I want to access.
This is what I have so far
#!/bin/sh
ssh -N -l my_username -i ~/.ssh/id_rsa_ssh -L <port>:<ip>:<port> <forwarding_ip> > /dev/null 2>&1 < /dev/null &
open -a Firefox http://localhost:<port>/url/to/something/secure
The ssh connection opens, but the browser can't establish a connection. Is there any way to programmatically open an ssh connection, background it, and ensure it stays open?
You wanted
autossh
.