04 December, 2008

SSH Tunnel Through Multiple Servers

For example, you want to use sftp connect to server C. Because of the security reason, you can not access server C directly from your local machine. Finally you figure a route, the only way to access to server C is local->A->B->C.
How do we set up ssh tunnel through these servers(using OpenSSH)?
1. on your local machine
ssh -f -N -L2000:localhost:2000 user@A
2. on server A
ssh -f -N -L2000:localhost:2000 user@B
3. on server B
ssh -f -N -L2000:localhost:22 user@C
Done! Now you can connect to localhost:2000 to access server C.

P.S. Pexpect is a nice python module to interact with apps through ssh.

No comments: