Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have 2 servers, A and B. I want to create a tunnel from my system to server B but I have some limits to do this. So I have to first tunnel to server A and from server A to server B. My goal is to have a SOCKS Proxy to browse the web.

How can I do this?

share|improve this question
up vote 5 down vote accepted

I am showing you a very basic way to do it. Here I am assuming that B is directly accessible from A. There may be variations according to various situations.

On A:

ssh -D socks_port B

This will open up the port socks_port on A as a SOCKS proxy.

On your system:

ssh -L local_port:localhost:socks_port A

This will forward local_port on your system to port socks_port on A.

Then you can configure your browser to use SOCKS proxy on socket localhost:local_port

A one-liner would look like this:

ssh -t -L 1234:localhost:5678 FIRSTHOST ssh -D 5678 SECONDHOST

where FIRSTHOST and SECONDHOST have to be replaced by your hosts’ names or IP addresses.

In your browser you have to enter a socks proxy as:

share|improve this answer
Thanks, Using this command I have to first run command ssh -D socks_port B on server A. Right? – hpn Dec 9 '11 at 11:21
It doesn't work. I can't browse the web. It only asks password of server A and not B(I think it should ask the passwords for both servers because server A should connect to server B). – hpn Dec 9 '11 at 11:32
@hpnik +1 for your first comment. I am sorry. I think you are right in the first comment. First you need to open up the port on A as SOCKS proxy with -D. I am updating my answer because then my ssh command will also change. – Sachin Divekar Dec 9 '11 at 11:40
Thanks, Is it possible to write both commands in one line? – hpn Dec 9 '11 at 11:48
@hpnik try ssh -t -L local_port:localhost:socks_port A ssh -D socks_port B – Sachin Divekar Dec 9 '11 at 11:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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