Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am working on a remote cluster via ssh with the -X option, because I need to visualize data and graphs, over a vpn protocol. Sometime due to the instability of the internet connection I lose my session. They told me I could use vnc in order to not lose my current session, so that if the internet connection drops I can reconnect and continue with my previously open session.

What I do is to log in the remote cluster 'remote.cluster' and type

 vncserver :1

then I open another terminal on my system and I type

 ssh -C -NL 5901:remote.cluster:5901 myusername@remote.cluster &

Then I start vinagre on my system and I connect using ssh protocol. The problem is that I do not have x11 forwarding and I cannot open windows. If I try to connect using the vnc protocol with vinagre it doesn't connect, because I get something as connection timeout.

What should I do?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

In case we connect to a remote X-Server via VNC we have the advantage that the graphical application will stay running even when the SSH connection to the remote is down. We can then reconnect to resume the graphical application. See also:

To speed up reconnection we may combine the connection to the remote with an SSH session by using vncviewer from tightvncviewer Install tightvncviewer with the option -via. By this we can run on the remote server:

vncserver:0  ## or any other display number e.g. :1

to establish a connection on the viewer via an SSH tunnel:

vncviewer -via user@remote localhost:0

Doing so will need considerably more bandwith because the whole desktop will have to be transmitted from the VNC server. Therefore it may not really be a good idea for low bandwith connections but it may give you a somewhat better experience on high bandwith but unstable connections as compared with X-forwarding.

share|improve this answer
    
what I really want to do is, in the link you provide, what michael_n says in the second comment to the first answer, but it doesn't work for me because I am not able to reconnect with screen -r, maybe I am doing something wrong –  simona Nov 21 '12 at 12:29
    
I did what you say and the vnc is asking for a password, that I didn't set, so should I ask it to the remotehost administrator, right? Another thing: if I use vnc via ssh as above in your answer, will it be slow because all the graphics drawing will be executed on the remote machine rather than my local one? –  simona Nov 21 '12 at 12:49
    
Vncviewer -via does ask 1) for the ssh password for the remote and then 2) for the vnc password but the latter only in case it was set on the remote. All drawing will be done on the remote server and then sent as a compressed graphic via the ssh tunnel (see also tightvnc.com/vncviewer.1.php) –  Takkat Nov 21 '12 at 13:25
1  
Thank you for your solution. Because it was not clear to me when I read your solution, I would like to point out to future readers that that the only necessary commands are vncserver :1 and vncviewer -via user@remote localhost:1. Btw the graphics visualization is very fast, I am surprised that it is actually riun on the remote cluster and not on my local machine –  simona Nov 22 '12 at 19:12
    
@simona: thank you for pointing at this. Hope with the edit it's clearer now. –  Takkat Nov 22 '12 at 21:32

The command used:

ssh -C -NL 5901:localhost:5901 myusername@remote.cluster &

forward local 5901 -> remote.cluster:5901

So you can connect to localhost::5901 to connect to the VNC session running on remote.cluster (which you don't have direct access to).

X11 forwarding is different from VNC. You need to use -X, for example

ssh -X myusername@remote.cluster

Than you will be able to run remote GUI applications on your local machine, provided that you have a X Server running locally (Ubuntu Desktop or Xming on Windows).

Update:

I made a mistake in the forwarding, it should be:

ssh -C -L 5901:localhost:5901 myusername@remote.cluster

Then you can vnc to localhost:5901, traffic will be forwarded to remote.cluster:5901. Apology for the carelessness...

If no GUI is required, consider using tmux or screen to avoid loss of session.

share|improve this answer
    
I always use ssh -X and it works, the point is that I would like to set up the thing in a way that when my connection drops I can reconnect and find again my previous session. So, are you saying I should use vnc protocol in vinagre to connect to the remote cluster? it does not work: I get `connection to host remote.host was closed' –  simona Nov 21 '12 at 12:00
    
I updated the reply, I didn't notice a mistake in the forwarding command. –  Terry Wang Nov 22 '12 at 9:25
    
Thank you, I do not really need GUI, just to visualize some plots, can you give me a starting point for screen or tmux, I do not know anything about them –  simona Nov 22 '12 at 12:51
    
I personally prefer tmux, you can use screen or byobu (Ubuntu enhanced screen), similar. Running tmux on the remote server is basically running a daemon/session on that box, so that when you get disconnected, you will be able to reconnect via SSH and attach to that session - tmux attach without losing what you were working on in terminal. A sample .tmux.conf gist.github.com/3950393 –  Terry Wang Nov 22 '12 at 21:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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