# VNC over SSH...

## VisualPhoenix

Can anyone think of a way to do this better than the following script?

```

#!/bin/bash

# usage: x11vnc_ssh <user>@<host>:<xdisplay>

host=`echo $1 | awk -F: '{print $1}'`

disp=`echo $1 | awk -F: '{print $2}'`

ruser=`echo $1 | awk -F@ '{print $1}'`

case "$ruser" in "") u="$USER" ;; *) u="$ruser" ;; esac

cmd="x11vnc -display :$disp -q -shared -dontdisconnect -rfbauth .vnc/passwd rbwait 5000"

enc="copyrect tight hextile zlib corre rre raw"

ssh -l $u -f -L 5900:localhost:5900 $host "$cmd"

sleep 2

vncviewer -encodings "copyrect tight hextile zlib corre rre raw" :0 &

ssh -l $u $host "pkill x11vnc"

#end of script

```

Granted you have to have a .vnc/passwd set up for your vnc password first, but I don't know of an easier or more reliable method at this moment.

I like x11vnc from the libvncserver package because it allows me to get windows esq vnc desktop session grabbing from my home pc... Obviously this is not the desired useage for a multi-user remote terminal service type setup, but it works well for a single user...

----------

## mico++

I used to do it with a mix of inetd, ssh, vnc and xdm

I found a link by searching for x11 vnc xinit xdm ssh on google and found a recipe to something that is quite similar to what I had done:

http://www.netraverse.com/member/downloads/miscfiles/vnc_recipe.html

My setup was nearly the same except for win4lin, I don't remember having to do anything special with xdmcp, but I was also using debian back then.  Also, I think your script connects you to a run session.. right? I can't tell.  Anyways, this might help...

I'll cut and paste the whole article for archiving purposes:

Recipe for setting up a VNC server to serve Win4Lin sessions.

The basic idea is to set up a server with a tightvnc server installed. This server will accept connections on the display numbers you choose to set up, but rather than one session per port, it will automatically create new servers as the connections come in, and provide the user with a xdm (or gdm/kdm) login screen. 

Here are the steps to set it up. 

Install xdm/kdm/gdm and tightvnc server 

Set up the /etc/services (as many as you like, 5900 = :0, 5901 = :1, etc):

```

xvncsmall       5950/tcp                        # Xvnc

 xvncmed         5951/tcp                        # Xvnc

 xvnclarge       5952/tcp                        # Xvnc

 xvnchuge        5953/tcp                        # Xvnc

```

Set lines like this in inetd and below in xinetd if appropriate, then restart inetd or xinetd. 

```

for inetd:

 xvncsmall       stream  tcp     nowait  nobody  /usr/sbin/tcpd \

     /usr/bin/X11/Xvnc -geometry 640x480 -desktop win -once -broadcast -inetd

 xvncmed         stream  tcp     nowait  nobody  /usr/sbin/tcpd \

     /usr/bin/X11/Xvnc -geometry 800x600 -desktop win -once -broadcast -inetd

 xvnclarge       stream  tcp     nowait  nobody  /usr/sbin/tcpd \

     /usr/bin/X11/Xvnc -geometry 1024x768 -desktop win -once -broadcast -inetd

 xvnchuge        stream  tcp     nowait  nobody  /usr/sbin/tcpd \

     /usr/bin/X11/Xvnc -geometry 1600x1200 -desktop win -once -broadcast -inetd

```

 or for xinetd:

```

 service xvncsmall

 {

        flags       = REUSE NAMEINARGS

        socket_type = stream

        protocol    = tcp

        wait        = no

        user        = nobody

        server      = /usr/sbin/tcpd

        server_args = /usr/bin/X11/Xvnc -geometry 640x480 -desktop win -once -query localhost -inetd

 }

 service xvncmed

 {

        flags       = REUSE NAMEINARGS

        socket_type = stream

        protocol    = tcp

        wait        = no

        user        = nobody

        server      = /usr/sbin/tcpd

        server_args = /usr/bin/X11/Xvnc -geometry 800x600 -desktop win -once -query localhost -inetd -depth 16

 }

 service xvnclarge

 {

        flags       = REUSE NAMEINARGS

        socket_type = stream

        protocol    = tcp

        wait        = no

        user        = nobody

        server      = /usr/sbin/tcpd

        server_args = /usr/bin/X11/Xvnc -geometry 1024x768 -desktop win -once -query localhost -inetd -depth 16

 }

 service xvnchuge

 {

        flags       = REUSE NAMEINARGS

        socket_type = stream

        protocol    = tcp

        wait        = no

        user        = nobody

        server      = /usr/sbin/tcpd

        server_args = /usr/bin/X11/Xvnc -geometry 1600x1200 -desktop win -once -query localhost -inetd -depth 16

 }

```

Set up xdm to broadcast xdcmp (may not be needed) 

```

vi /etc/X11/xdm/xdm-config

   if there is a line : "DisplayManager.requestPort: 0" comment it out

   with a ! in col1 and restart xdm

 vi /etc/X11/xdm/Xaccess

   add a line to allow the hosts you want to get xdcmp (i.e. a line with

   '*' in col1)

```

This would also apply to gdm and kdm but I don't have the recipie for that right now. 

For each user that you want to auto-launch win4lin, make a ~/.xsession symlinked to ~/.Xclients that has simply this in it: 

#!/bin/sh

 exec win --fwin

alternatively you can add a session type for windows that does that same command for gdm/kdm session. 

That's it, you can now connect to the server with a vnc or tightvnc viewer using the examples above :50, :51, :52, :53. 

vncviewer servername:50

To connect to the server via an ssh tunnel from a linux/unix tight vnc client: 

vncviewer -via sshhost servername:50

where sshhost is a host running sshd and servername is the server you just set up. 

To use the tunnel from windows, or from unix with a regular vnc client, you must first get an ssh daemon to port forward the port you are interested in like this: 

ssh -L 5950:servername:5950 sshhost

then launch vncviewer and connect to localhost:50[/quote]

----------

## mico++

Ah, I just saw that this was covered in a thread already.  Sorry!

----------

## slimpinto

I'm not entirely sure this is what I want/need to do???

All I want to do is be able to see my KDE desktop over my VNC connection. So far I am able to get to my gentoo server from work just fine, but it uses TWM. What configuration do I need to accomplish this? Mind you, I already have a working ssh/vnc connection...

(If this has been convered in another post already, my apologies...I did search, but not able to find the solution to my problem!)

Thanks...any help will be greatly appreciated!

----------

## capran

I'm able to ssh into my box, and then simply tunnel vnc through my ssh shell on my work Windows box. That way I can close all internet ports on my machine except SSH, FTP and HTTP. Much more secure. I run x11vnc -display :0 from the ssh shell and it works great.

The only problem I have though is that it only works if I've already logged in with KDM locally and my KDE session is up and running. If I reboot the machine or log out or whatever, it won't work. From the ssh session I can see that KDM login is working, but can't use x11vnc to connect.

Does anyone know how to get that to work?

Also, I have a problem with keyboard entry from work, where keys will often repeat over the vnc connection. Very annoying. And its even worse when I'm logging in to the box from my LAN connected Powerbook to the box. There's a huge delay in keyboard and mouse response, I can't figure it out.

----------

## slimpinto

CORRECTION: Now that I've upgraded to 2004.3 and have more Gentoo experience, I realized this did NOT fix it for me. I was only vnc'ing to my home box, not tunneling through ssh too! I have a new thread on the subject in the Desktop Environments section...

I'm all set from the answer I received over here:

https://forums.gentoo.org/viewtopic.php?t=169681&highlight=

WOOT!

----------

