We have a serverA to connect to. Then we use serverA to connect to databaseB. Setup like this in Putty (windows):

Session1:
1. connect to admin@serverA
2. setup tunnel local port 10022 to databaseB:22
3. run 'vi'

Session2:
1. connect to admin@localhost:10022
2. setup tunnel local port 1521 to database 1521
3. run 'vi'

(vi is used to hold session)

Then program use localhost:1521 for database connection.

I wonder if I can do it in a single command or a batch file in cygwin? Note that I cannot open port on serverA

link|improve this question
feedback

migrated from stackoverflow.com Mar 6 '11 at 10:11

This question came from our site for professional and enthusiast programmers.

3 Answers

I'd try running:

ssh admin@serverA -L 10022:databaseB:22
ssh admin@localhost -p 10022 -L 1521:database2:1521

But man, I cringe even suggesting it. The people who firewalled off DatabaseB probably had a good reason for doing so. Talk with them.

link|improve this answer
feedback
ssh -L 1521:127.0.0.1:61521 admin@serverA ssh -L 61521:127.0.0.1:1521 admin@databaseB

or using plink (Putty link) from a command window:

plink -ssh -L 1521:127.0.0.1:61521 admin@serverA ssh -L 61521:127.0.0.1:1521 admin@databaseB
link|improve this answer
feedback

As to running this as a single command, the previous answer is correct but if the second ssh requires a password, it will probably not work (depending on ssh default configuration). You will have to force the allocation of a pseudo-tty by using the -t option, as in:

ssh -t -L 1521:127.0.0.1:61521 admin@serverA ssh -L 61521:127.0.0.1:1521 admin@databaseB

(this works using cygwin's ssh command)

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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