# x11vnc: Connect to a Running Desktop Easily

## OdinsDream

http://www.karlrunge.com/x11vnc/

I've had this question ever since I installed linux. How do I connect to my running desktop remotely, exactly like VNC does on Windows (which is where I first started using vnc)?

Through the forums here, I had read about x0rbserver (not sure if that's spelled correctly..) and even tried it a few times, but I was still puzzled by the lack of a "built-in" ability to do this naturally with vnc. It just didn't make sense.

So, here's the quick steps to getting this working with very little hassles (and very little security, but the above URL covers that):

[home machine]$ emerge libvncserver

[home machine]$ x11vnc -display :0

[public terminal]$ vncviewer <home machine>:0

...doesn't get much simpler than that, folks.

I'm not sure if the option at this link is known to everyone, but I just recently stumbled on it myself, and thought I'd share, as it's an excellent step-by-step howto. All that was necessary was to emerge libvncserver, and then grab a vncviewer to get started. I happened to already have tightvnc installed, which came with a viewer, but I'm sure the viewer can be downloaded separately (or just stick it up in a web-accessible place).

So, I'm not really sure why I hadn't heard mention of this, in my opinion, extremely simple method that seems to already be entirely built into libvncserver. Remember, tunnelling through SSH is a good idea. Hope this helps someone!

----------

## ShutterBC

Any idea why this seems to be much faster than using krfb?

----------

## OdinsDream

Heh, no idea. So far I've been very pleased with the performance, especially using tightvnc encoding. Even not using tightvnc, I was able to work on my home system from the office, which means going through two cable modems, both of which are heavily shared. The performance was much better than pcAnywhere.

----------

## zenon

here's some more VNC info if NE wants:

http://www.umanitoba.ca/acn/unix/software/vendor_html/vnc/documentation.html

everything in linux 'flava' is better/faster, that's just a fact of life!

----------

## zenon

I have ports 5900-5910 opened on my firewall (TCP and UDP) and get this error:

```
root@zen zenon # vncviewer mycomp.com:0

vncviewer: ConnectToTcpAddr: connect: Connection refused

Unable to connect to VNC server
```

does that mean I need to change my firewall settings?

----------

## OdinsDream

Are you sure the x11vnc program was able to use ports in that range? The firewall would definitely be something to check, but first make sure the ports are right. x11vnc should print out what it's using when started.

----------

## Farkenell

https://forums.gentoo.org/viewtopic.php?t=72893

I think this is what you maybe lookin for?

was pretty easy to do...I got it first go...

----------

## OdinsDream

Farkenell, I believe the difference between this thread and the one you linked is the fact that this one is for connecting to a currently running desktop. It's not a terminal server, like the other one. Both have their uses, and I've made use of the terminal server type of installation before, but this thread is only useful if you want to connect to your screen as you left it.

So, if you started GAim at home, this thread shows you how to connect to the system and see the -currently running- gaim session.

The thread you link to allows you to connect to the home system, but start up a brand new session. You don't interfere with the applications currently running, and in fact, can't interact with them.

----------

## CriminalMastermind

well i don't have vnc setup to connect to my :0 display, but it appears there is another way to do this.  here is the link from the realvnc ver 4 faq.... incase anyone wants to know another way this could be done.

----------

## RexM

 *ShutterBC wrote:*   

> Any idea why this seems to be much faster than using krfb?

 

 *http://www.karlrunge.com/x11vnc/ wrote:*   

> x11vnc is written in plain C and uses only standard libraries.

 

That could possibly be the reason  :Wink: 

----------

## Entropy42

Just curious:

Will things that normally run very slowly over VNC (video, 3D acceleration) work on the local display when doing this?  Or will they be slow locally also.

i.e. if I set this up, will I be able to run xine and quake3 when sitting locally at the machine, but be able to connect and use non-video/3D apps when connecting remotely?

----------

## OdinsDream

Entropy42, vnc works by monitoring your local screen for changes and then sending only those blocks that change to the remote client. When I'm using vnc on the 10mbps LAN here, it's only slightly slower than actually sitting at the machine. When I connect to home from the office, it's usable, but things like scrolling, or dragging an entire window, are noticeably slower and should be avoided.

That being said, things like XINE and 3D acceleration are a different matter altogether. In general, the content in video windows will not show up on the remote viewer, simply because of the more efficient way the video player deals with your video memory. I don't know at all how it technically works, but it's called "overlay," and that only works locally. The same would go for 3D acceleration. It does not, however, slow down the response at all. The video content simply doesn't get copied to the remote viewer. In its place will be a black (green, fuscia) box.

----------

## skwashy

Any idea why x11vnc quits when my remote viewer closes?

Maybe I missed something?

```
observer root # x11vnc -display :0

viewonly:   0

shared:     0

conn_once:  1

mod_tweak:  0

loc_curs:   1

mouse:      0

root_curs:  0

defer:      30

waitms:     30

take_naps:  0

threads:    0

fs_frac:    0.60

gaps_fill:  4

grow_fill:  3

tile_fuzz:  2

use_hints:  1

Using display :0

Read initial data from display into framebuffer.

using 16bpp depth=16 true colour

16/10/2004 01:24:30 Autoprobing TCP port 

16/10/2004 01:24:30 Autoprobing selected port 5900

PORT=5900

screen setup finished.

16/10/2004 01:24:44 Got connection from client 192.168.1.20

16/10/2004 01:24:44   other clients:

16/10/2004 01:24:44 Protocol version 3.3

16/10/2004 01:24:44 Pixel format for client 192.168.1.20:

16/10/2004 01:24:44   8 bpp, depth 8

16/10/2004 01:24:44   true colour: max r 7 g 7 b 3, shift r 0 g 3 b 6

16/10/2004 01:24:44 Using ZRLE encoding for client 192.168.1.20

viewer exited.

observer root # 
```

----------

## OdinsDream

skywashy, that's the default behaviour. If you want to leave the connection open for the next client, start the server like this:

x11vnc -forever -display :0

...mentioned here.

----------

## Sugarat

I've emerged x11vnc but when I try to run it it is saying 

```

11/02/2005 13:22:13 x11vnc version: 0.7pre lastmod: 2004-12-23

Xlib: connection to ":0.0" refused by server

Xlib: No protocol specified

11/02/2005 13:22:13 XOpenDisplay failed (:0.0)

```

----------

## LeTene

A tip here that should work with any VNC variant - use SSH tunneling to avoid having to open any 59xx ports.  I use Windows XP at work, so I use PuTTY to do the job for me. You'll need your SSH port open in the firewall, but I think most people will aready have this set up...

Assuming that the VNC server on your home machine runs on display :1 (which usually equates to port 5901) this works great for me:

In PuTTY's Tunnels section, enter 5901 into the Source port box, localhost:5901 into the Destination box, and then press the Add button (you'll see L5901 localhost:5901 appear in the listbox just above those edit boxes).

Now go back to PuTTY's Session section, fill in your home machines address and connect & log in. You now have a tunnel connecting your local work machines port 5901 to your remore home machine.

Now fire up your Windows VNC client, and for the Server, specify localhost:1, press your Connect button and enter your password.

That's it!

----------

## dezydery

Sounds good... but can this also be done with FreeNX (i.e. connect to running X session)?

----------

## cron0

Emerged libvncserver: emerge -v libvncserver

But it produced NO x1vnc binary. 

Any clues?

Edit: got it, it is now called "x11vnc!" .... emerge x11vnc

----------

## Xamindar

Hey I emerged this put it will not run.  Anyone else have this problem?

```
illusion init.d # x11vnc -display :0

Settings:

 display:    :0

 authfile:   null

 subwin:     0x0

 -sid mode:  0

 flashcmap:  0

 force_idx:  0

 visual:     null

 overlay:    0

 ovl_cursor: 1

 scaling:    0 1.00000

 viewonly:   0

 shared:     0

 conn_once:  1

 timeout:    0

 inetd:      0

 connect:    null

 connectfile null

 vnc_conn:   1

 allow:      null

 input:      null

 passfile:   null

 accept:     null

 gone:       null

 users:      null

 using_shm:  1

 flipbytes:  0

 onetile:    0

 solid:      null

 blackout:   null

 xinerama:   0

 xrandr:     0

 xrandrmode: null

 padgeom:    null

 logfile:    null

 logappend:  0

 rc_file:    ""

 norc:       0

 bg:         0

 mod_tweak:  1

 isolevel3:  0

 xkb:        0

 skipkeys:   null

 addkeysyms: 0

 xkbcompat:  0

 clearmods:  0

 remap:      null

 norepeat:   1

 nofb:       0

 watchbell:  1

 watchsel:   1

 watchprim:  1

 cursor:     1

 multicurs:  0

 curs_mode:  null

 xfixes:     1

 alphacut:   240

 alphafrac:  0.33

 alpharemove:0

 alphablend: 1

 cursorshape:1

 cursorpos:  1

 xwarpptr:   0

 buttonmap:  null

 dragging:   1

 ptr_mode:   2

 inputskip:  10

 speeds:     null

 debug_ptr:  0

 debug_key:  0

 defer:      30

 waitms:     30

 take_naps:  1

 sb:         60

 sigpipe:    null

 threads:    0

 fs_frac:    0.75

 gaps_fill:  4

 grow_fill:  3

 tile_fuzz:  2

 snapfb:     0

 gui:        0

 gui_mode:   null

 noremote:   0

 safemode:   1

 deny_all:   0

 

13/03/2005 09:50:06 x11vnc version: 0.7.1 lastmod: 2005-02-23

Xlib: connection to ":0.0" refused by server

Xlib: No protocol specified

 

13/03/2005 09:50:06 XOpenDisplay failed (:0)

illusion init.d #      
```

----------

## Xamindar

Ok, I got it.  It just couldn't find the xauthority file which was located here:

```
/var/lib/xdm/authfiles/A\:0-usXZLI
```

strange file name but it worked.

Can someone help me out with getting it to load on boot?  This looks like a random xauthority file so I would probably need a startup script that would get the xauthority each time.  I have no experience with scripts though.

Anyone already doing this?  Or is there a better way to have an vnc-able X server?

EDIT:  yes, that xauthority file's name changes on each reboot.  How can I input that into the x11vnc command automaticaly?

----------

## Danuvius

 *OdinsDream wrote:*   

> So, here's the quick steps to getting this working with very little hassles (and very little security, but the above URL covers that):
> 
> [home machine]$ emerge x11vnc
> 
> [home machine]$ x11vnc -display :0
> ...

 

Thanks!  This works great for me.  I've been looking for a simple way to use my at-home work machine (gentoo) from my at-home family computer (windows xp).

 *OdinsDream wrote:*   

> So, I'm not really sure why I hadn't heard mention of this, in my opinion, extremely simple method that seems to already be entirely built into libvncserver. Remember, tunnelling through SSH is a good idea. Hope this helps someone!

 

Having said that, literally all I did was what you have above.  Is my connection terribly insecure?  I am behind a router, so I'm not terribly paranoid.  But at the same time, I am not looking to have a 'please hack me' setup either.  How do I do the ssh tunneling?

Lastly, my one woe with this: I cannot type a double quote (e.g.: ").  (That one was copied and pasted.) When I press shift+' I still only get '.

Admittedly this might be the fault of the vnc program I am using to connect.  Still, thought I'd mention it in case someone has ideas.

Sincerely,

Danuvius

----------

## gaboonal

I have two computers, one running Gentoo and one running Windows XP. The one running Windows has 256MB RAM and a 650MHz CPU and the one running Gentoo has 1GB RAM and a 3.2GHz CPU. On a 100Mbps LAN, when I connect to the one running Gentoo from the one running Windows or vice versa I get 100% CPU when moving Windows, scrolling etc. on the computer running Windows. This is the case even with compression disabled. Both machines are running TightVNC.

Is there a way to make this usable? If not, is there an alternative? I need to be able to log onto the current X session. Can this be achieved with a normal X server?

----------

## dewke

 *gaboonal wrote:*   

> I have two computers, one running Gentoo and one running Windows XP. The one running Windows has 256MB RAM and a 650MHz CPU and the one running Gentoo has 1GB RAM and a 3.2GHz CPU. On a 100Mbps LAN, when I connect to the one running Gentoo from the one running Windows or vice versa I get 100% CPU when moving Windows, scrolling etc. on the computer running Windows. This is the case even with compression disabled. Both machines are running TightVNC.
> 
> Is there a way to make this usable? If not, is there an alternative? I need to be able to log onto the current X session. Can this be achieved with a normal X server?

 

You need to up the ram on your XP box.  My laptop only had 256mb and XP was barely usable until I added more ram.

----------

## ikke

If you're running Gnome you get this functionality automagically through Vino.

----------

## gaboonal

Upgrading the RAM is not an option unfortunately. I don't run gnome, I run fluxbox. I now have Ubuntu Linux running on the slower machine on dual boot.

----------

## thomasa88

thx for the tips

if ya want a password u can add -rfbauth

but first u need to create a encrypted passfiel with storepasswd (unfortunately u have to write the password in cmdline)

----------

## Kwai

This seems to be what I was looking for but I run into the same problem as when using the Gnome built in desktop sharing. When I use VNC to connect to the computer I don't get a full use of my keyboards char set.

When using a keyboard plugged into the computer I can type ÞÆÐÁÖ etc. as well as keys that require AltGr to be pressed @[]{}. This is a icelandic keyboard btw.

When using vncserver to start a session I get full use of these keys as well, but I want to connect to the existing screen session so not much use there.

So when connecting to the existing Gnome session via VNC there is something lost in translation.

Any suggestions?

----------

## pjp

This works, but seems really, really slow for redrawing.  And I've yet to add ssh.   :Sad: 

----------

## Redeeman

krfb uses libvncserver, and shouldnt be slower

----------

## Moloch

I've been using xf4vnc for this kind of stuff. It's very fast and runs with Xorg just fine.

----------

