9

I use

ssh -D 1080 myhost.org

...to open up an SSH tunnel from my work machine to my home machine, so as to bypass the idiotic content filter on the corporate firewall. However this also creates an interactive SSH session that lives the whole time I'm using the tunnel. Is there any way to tell SSH just to create the tunnel and not bother with the interactive session?

dirtside
  • 1,481
  • 4
  • 17
  • 22

3 Answers3

13

Seems like you want the -N flag.

ssh -D 1080 -N myhost.org
andol
  • 6,848
  • 28
  • 43
  • 5
    It's recommended to use -fnN in conjunction. – kolypto Nov 26 '09 at 01:46
  • 1
    I'd even recommend to use autossh to manage reconnects in such cases. – jollyroger Jun 19 '12 at 12:18
  • How do you stop the ssh connection in this case? When you're done with that remote endpoint and want to connect to something else on that port? – Mnebuerquo Jan 04 '18 at 20:28
  • @Mnebuerquo For ad-hoc tunnels I simply kill the process when I'm done with the tunnel. For more commonly used tunnels I have them defined as systemd --user units. – andol Jan 06 '18 at 17:33
4

from ssh manpage:

 -N      Do not execute a remote command. This is
         useful for just forwarding ports (protocol version 2 only).
dschulz
  • 206
  • 3
  • 7
3

I've typically found this to be better because it not only stops listening to commands, but also goes into the background.

SSH -D 1080 -N -f yourhost.org
Hengjie
  • 2,853
  • 1
  • 15
  • 10