Home > Development > Getting Capistrano's SSH method to work behind a SOCKS proxy

Getting Capistrano's SSH method to work behind a SOCKS proxy

At work we've got a bit of an annoying proxy setup. It does allow outbound SSH through a SOCKS 5 proxy (no auth), and after a while of Googling (I don't know Capistrano nor Ruby, but the Ruby app developer did) we were able to figure it out.

Assuming you have the Net::SSH::Proxy::SOCKS5 class installed on your system (which may come as part of net-ssh?) it's actually quite simple. Getting the ssh settings right took a while of looking around, but it wound up being quite easy, and since I could not find anything on the net about this, I wanted to post our findings.

It's as simple as adding the following to the applications's config/deploy.rb:

require 'net/ssh/proxy/socks5'

sshproxy = Net::SSH::Proxy::SOCKS5.new('proxy.com', 1080)
set :ssh_options, { :proxy => sshproxy }

Viola.

Obviously there are more options, but we had a hell of a time trying to correlate the options and get them fed into the SSH module (if that's the right term) properly. It'd probably be much simpler if I had known Ruby, or if this problem was in PHP 🙂 Anyway, I try to share what I can when I get it... (this post is only over four months overdue...)

Enjoy!

Categories: Development