Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.


I have a VNC server (x11vnc) configured to allow me to log into the machine at the local display (:0) via SSH tunnel, following the instructions here.
My question: is there a way to create the tunnel AND launch vncviewer with a single command/script?

Here's how I'm launching x11vnc from /etc/gdm/Init/Default:

x11vnc -localhost -nopw -ncache 0 -o /var/log/x11vnc.log -forever -bg

Edit: please note that in this way x11vnc starts from gdm, so that I can log into the local session myself.

(Server and client: Xubuntu 9.04)

share|improve this question
add comment

2 Answers

up vote 6 down vote accepted

The vncviewer can connect on it's own through SSH, so a shorter command would be:

vncviewer -via username@hostname.tld localhost:x

On the above, x is your local display (0, 1...).

share|improve this answer
    
Very convenient, thanks :) I still have the "disconnects after login" problem though.. Maybe the only way for that is to use two terminals.. –  Joril May 5 '09 at 11:50
2  
Setting up VNC as a remote terminal service requires a bit of footwork, but you might be better off installing the tightvnc package instead. Not only does it have slightly better options but it also supports compression, a must-have for remote work over slow internet connections (tunneling with SSH, of course). Also, I believe that there is a command option that discourages disconnects...can't recall ATM... –  Avery Payne May 5 '09 at 12:53
add comment

Note: untested

try this

ssh host -f -L5900:localhost:5900 "sleep 10000000000" && vncviewer localhost:5900
share|improve this answer
    
Thanks for your suggestion, but x11vnc is already running.. I edited the question to clarify this :) –  Joril May 5 '09 at 8:57
    
Right, updated my response. Someone can probably find a better noop command than sleep 1000000000 –  Dave Cheney May 5 '09 at 9:05
    
This works fine, thanks! I'll look for a way to close ssh when the vnc connection gets closed.. Anyway, now the only remaining problem is logging in.. When I enter user and password vncviewer exits and if I try to reconnect, the login screen is still there.. If I use two terminal windows instead (one for the SSH tunnel and one for VNC) I can login just fine.. :/ –  Joril May 5 '09 at 9:43
add comment

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.