How do I pass commands (shell) to a persistent SSH tunnel rather than open a connection for every instance? I have a Python scraper running on a client server which passes URL variables and shell commands to a remote host via a reverse tunnel (forwarded port), so that the URL's are then executed on the host (python > fabric > ssh localhost:12345 'browser open URL'). I could make the reverse tunnel persistent but how do I echo the url/command to the session?

Update - ControlMaster (built into SSH) solves this one.

  • when you say 'commands' do you mean shell commands, or is the command itself the URL in question (eg: its just data)? are you connecting to a server-side service using ssh as your carrier, or are you just executing shell commands as part of an ssh session? – Frank Thomas Nov 30 '12 at 3:52
  • I found what I was looking for, for now (see below). In response it's a shell command, sent to the host through SSH, in this example ssh -p 00000 localhost 'DISPLAY=:0.0 firefox %s' %URL. I'm still learning to walk and I don't think using SSH will be the best way as things get heavier so any suggestions are appreciated. But for now this works and saves messing about with queues. – woowaa Nov 30 '12 at 4:47

I just discovered ControlMaster which is built into later SSH versions and reuses existing connections if they exist:


Great stuff. I might look into proxies and what not when things get a bit heavier so any advice on developing this is appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.