LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   SSH Tunnel Forwarding with no shell (https://www.linuxquestions.org/questions/linux-server-73/ssh-tunnel-forwarding-with-no-shell-818962/)

Unixscript 07-09-2010 03:09 PM

SSH Tunnel Forwarding with no shell
 
Hi Experts,

I am trying to have the SSH tunnel Remote forwarding command in a shell script. I should be able to do 2 tasks, but unable to get that going.

1) I have 3 servers Server 1, Server 2, Server 3.

I have my Database running on Server 1 and my script running on Server 2 which should be able to do port forwarding from Server 1 to Server 3.


so for example on Server 2

ssh -i $ssh_key -R 9000:Server1:3333 root@Server2.

I need to be able to stick this in a shell script something like
getTunnel()
{
echo "HOST"
echo "Creating HTTP Tunnel to Instance in the background"
ssh -T -t -i $ssh_key -R 9000:Server1:3333 root@$HOST & <<EOF
mysqladmin -u root -S /tmp/mysql-DB.sock start-slave

EOF

echo "Tunnel Create"
}

2) In this second task not be able to get the shell prompt of the Server 3 but pass some commands to execute on the remote server.


Can someone please be able to help me through with this. That should be very helpful. I have been stuck with this problem for many days with out a solution.

Thanks.

tkmsr 07-10-2010 12:58 AM

There is some thing known as nc for such situation in case of server2.

in this situtation it is common to setup the users .ssh/config file to use an ssh proxy so they can just ssh instead of sshing to server2 and then server3

Code:

Host server2.yourwork.com
user foomaster
ProxyCommand ssh server3.yourwork.com nc server2.yourwork.com 22

this command uses nc to connect to server3 from server2


All times are GMT -5. The time now is 06:20 PM.