0

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:127.0.0.1:5900 -p 1200 [email protected] (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.

1 Answer 1

2

Try:

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 
Sign up to request clarification or add additional context in comments.

9 Comments

Which part do I replace with that?
My understanding is this: You have a local linux system & you want to view vnc of a remote linux system. If yes, the 2 commands should suffice your requirement, to replace all 4 commands. If your vncviewer supports -via parameter, it will do the tunnelling business behind the scenes.
Ah no. The problem is that I can't access the remote system directly and in fact I can't even access 5900 from the intermediate machine. This is why I have to do this complicated tunelling.
can you ssh remote system? or is it a 2 hop case?
2 hops always . I should say my method works. I just want to automate in a bash script somehow.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.