Thursday, September 13, 2007

Running an SSH Tunnel in the background

nohup ssh -v -L <local.port>:<destination.ip>:<destination.port> username@<remote.ip>

Note: You cannot use an alias for the ssh command or else it will not work. You must use the ssh command directly in the nohup command.

3 comments:

Matteo Brutti matteo.brutti@gmail.com said...

Why have you wrote about a tunnel in background? This command don't put ssh tunnel in background. It makes a tunnel in verbose mode.

To create a tunnel in background give:
ssh -f -N -L localport:destination.ip:destination.port username@ssh_server.ip

where -f forces ssh to run in background but in this case it wants a command to execute, if you only want to create a tunnel, give the -N that indicates that's no command to be execute or only the tunnel

Best regards.

Matteo Brutti

Anonymous said...

Guys, what about leaving that connection on cycle, so that it would reconnect on disconnection?

bronius said...

Anonymous: To keep it "on cycle" look into autossh. Params are similar to ssh (in fact they're just passed in), but has additional params like ssh monitoring port and number of seconds for timeout or retry. I use autossh for persistent ssh tunnel.