Run Port-forwarding Sessions with Screen
Use screen
to run long-running commands, such as port-forwarding ssh
sessions, on your local or remote machines.
As opposed to nohup
shenanigans, the advantage here is that this is just like a terminal session, but out of sight. The session is addressable, recallable by name.
Scenario: You make a remote port available locally. You run a bunch of operations on the service now available at your local port. You terminate the port-forwarding.
After running ./connect.sh
, the remote service running on port 8002
becomes available locally. If for any reason the ssh
command fails, the screen terminates.
You can always inspect the status of your session with screen -r ${SCREEN_NAME}
.