LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 01-22-2008, 06:19 AM   #1
rafa_gallego
LQ Newbie
 
Registered: Jul 2007
Location: Gijón - Asturias - Spain
Distribution: Fedora & Mandriva
Posts: 11

Rep: Reputation: 0
help with ssh tunneling


Hi,

my problem is pretty simple and I am sure that some of you can help me with it. I want to make a script to connect via ssh to a remote host not reachable directly from my computer. However I have ssh access to a computer with ssh access to the target host.

Schematically:

host1: my PC
host2: A host reachable via ssh from host1
host3: A host reachable via ssh from host2 but not from host1

¿How connect host1 to host3 vis ssh? The solution you may think of is a ssh tunnel. I know how to set up this tunnel from the command line but not from within a script, and this is why I am asking for help.

From the command line (from host1):

1) [user@host1 ~] ssh -L 9999:host3:22 user@host2
After entering my password a prompt

[user@host2 ~]$

appears.

2) Now, in another terminal I execute

[user@host1 ~] ssh -p 9999 localhost
and, after entering the user's password I can enter host3.

The problem is to arrange this in a script. The reason being that the ssh tunnel set up in step 1) is in the foreground. If I could to put the ssh connection in the background perhaps I could get what I want.

Rafael Gallego
 
Old 01-22-2008, 10:45 AM   #2
rafa_gallego
LQ Newbie
 
Registered: Jul 2007
Location: Gijón - Asturias - Spain
Distribution: Fedora & Mandriva
Posts: 11

Original Poster
Rep: Reputation: 0
Well, readind carefully the man page of ssh I have found a workaround, which is just using the option -f and executing the command sleep. In this way, the tunnel would be set up as follows:

ssh -f -L local_port:host3:22 rgallego@host2 sleep 10

In this way, the ssh goes to the background and give me 10 seconds before it exits.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Tunneling with ssh ssherman Linux - Networking 3 07-16-2007 02:13 AM
tunneling thru ssh c9876543210 Linux - Networking 1 07-21-2005 12:45 AM
X tunneling with SSH phekno Linux - Networking 3 05-31-2005 10:43 AM
SSH tunneling X AzZuM Linux - Security 3 11-27-2004 01:59 AM
tunneling with ssh barbanero Linux - Security 2 01-24-2002 10:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 06:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration