How to automate a vnc+ssh solution

I would like to run an application (call it firefox) on my work machine. The problem is that I need to do some complicated ssh tunelling to get access to it as access to the machine is blocked from the outside and some ports are also blocked internally. So I do the following.

ssh -v -L 1200:serverC:22 user@serverB (locally)
ssh -v -L 5900: -p 1200 user_from_serverC@ (locally)
x11vnc -safer -localhost -nopw -once -display :0 (on serverC)
vinagre localhost::5900 (locally)

I then run firefox (say) in the vnc window that opens and it all works.

However I would like to have a bash script that does this for me. How can I automate it?

There are two problems.

  1. I need to stay logged in after each ssh above for the tunelling to work so a simple bash script just stops after the first step.
  2. I don't know how to get an application to run automatically in a vnc window.

Ideally I would just type "./remote-firefox" (for example) locally to get all this to happen.



x11vnc -safer -localhost -nopw -once -display :0 #Run manually on system_C

& on local system,

ssh -t -L 5902:localhost:5901 user_B@server_B 'ssh -t -L 5901:localhost:5900 user_C@server_C' &
#Note: Enable password-less (key based) authentication from "your_pc -> servB" & "servB -> servC"

vncviewer localhost:2 #Run on local system

NOTE: If the commands fail, please try changing the port numbers. In this example, I am trying to tunnel it as below:

your_PC:5902 <-> server_B:5901 <-> server_C:5900

I have not tested this 2 level chain (I do not know if x11vnc's -display parameter works across ssh, but I think, it should.):

#Run both lines on local system
ssh -t -L 5902:localhost:5901 user_B@server_B "ssh -t -L 5901:localhost:5900 user_C@server_C 'x11vnc -safer -localhost -nopw -once -display :0'" &
vncviewer localhost:2

EDIT: To accomodate this:

yes that's it. But annoyingly servB -> servC has port 5900 blocked. – Anush

#Run both lines on local system. This may be overhead, but should work.
ssh -t -L 5902:localhost:5901 user_B@server_B "ssh -t -L 5901:localhost:1200 user_C@server_C 'ssh localhost -L 1200:localhost:5900 & x11vnc -safer -localhost -nopw -once -display :0'" &
vncviewer localhost:2

Need Your Help

Get Total Comment, Like, Share (PHP Facebook API v2.4)

php facebook facebook-graph-api facebook-php-sdk

I've read facebook documentation about comment and like but still confused how to get total comment, like and share from my facebook page feed.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.