Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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


Goal: you need to reach "Server B" from the Client "directly" with SSH, SCP.

"Server B" is next to "Server A". E.g.: they're on the same subnet, but only "Server A" is reachable from the Internet -> so "Server B" is only indirectly accessible.

I know how to use tsocks:

install tsocks

yum install tsocks

configure it [by default there is no config file..]

vim /etc/tsocks.conf
server =
server_port = 4000

create the ssh tunnel

ssh -v -fND localhost:4000 USERNAME@SERVER-A

check that if it's created

ps aux | fgrep -i ssh
USER      8894  0.0  0.0   9780   708 ?        Ss   11:58   0:00 ssh -v -fND localhost:4000 USERNAME@SERVER-A
netstat -tulpn | fgrep -i ssh
tcp        0      0    *                   LISTEN      8894/ssh

how to use tsocks

tsocks ssh root@SERVER-B

kill the ssh tunnel

kill `pgrep -f 'D localhost:4000'`

The whole thing is fully OK to me. Fine.

The Question: How can I use multiple ssh tunnels with e.g.: tsocks?
I mean I have to use several ssh tunnels (on different ports of course).
How can I set e.g.: tsocks to "memorize" several ssh tunnels (ports)?

The "/etc/tsocks.conf" file only allows one server, that's ok, because If I ssh tunnel to somewhere I have to go through, but I need more ports, because 1 port = 1 ssh tunnel. Several ssh tunnels can't bind to 1 port.
I'm using Fedora 14 for "Desktop PC"

Thank you!

share|improve this question
up vote 4 down vote accepted

tsocks allows multiple SOCKS services, you set it up to use a different SOCKS service (i.e. different ssh -D listening on a different port) for each desired target. man tsocks.conf for more details.

assuming /etc/tsocks.conf containing:

path {
    server = localhost
    server_port = 1081
    reaches = <ip-address-of-server-b>/32
path {
    server = localhost
    server_port = 1082
    reaches = <ip-address-of-server-d>/32

Then you would run

ssh -fND :1081 server-a & sleep 1 ; tsocks ssh server-b
ssh -fND :1082 server-c & sleep 1 ; tsocks ssh server-d
share|improve this answer

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.