19

I would like using ssh tunneling options. For that purpose I use command:

ssh -L 1234:localhost:5678 host

however this logs me into the shell on remote host. Next I tried -f as:

 ssh -f -L 8999:localhost:6006 host

but I get error Cannot fork into background without a command to execute.

How can I get only ssh tunneling capabilities and running it in background without unnecessary clutter. My ssh version is OpenSSH_7.2p2, OpenSSL 1.0.2h 3 May 2016

  • ssh -L 1234:localhost:5678 host 'sleep 30; logout' will give you 30 seconds to start whatever you need to start that needs the tunnel, and log out of the shell. The tunnel won't collapse until nothing is using it. – DopeGhoti Jun 10 '16 at 00:22

1 Answers1

26

Use the -N option

 -N      Do not execute a remote command.  This is useful for just for-
         warding ports (protocol version 2 only).

Example

ssh -fN -L 8999:localhost:6006 host