Difference between revisions of "X11vnc"

From ArchWiki
Jump to: navigation, search
(Running constantly)
(style)
 
(17 intermediate revisions by 11 users not shown)
Line 1: Line 1:
 
[[Category:Security]]
 
[[Category:Security]]
[[Category:Virtual Network Computing]]
+
[[Category:Remote desktop]]
 +
[[ja:X11vnc]]
 
[[zh-CN:X11vnc]]
 
[[zh-CN:X11vnc]]
{{Article summary start}}
+
{{Related articles start}}
{{Article summary text|x11vnc allows one to view remotely and interact with real X displays (i.e. a display corresponding to a physical monitor, keyboard, and mouse) with any VNC viewer. In this way it plays the role for Unix/X11 that WinVNC plays for Windows.}}
+
{{Related|TigerVNC}}
{{Article summary heading|Related Articles}}
+
{{Related articles end}}
{{Article summary wiki|Vncserver}} - Remote display server that allows users to run parallel sessions while NOT controlling the root display.
+
x11vnc allows one to view remotely and interact with real X displays (i.e. a display corresponding to a physical monitor, keyboard, and mouse) with any VNC viewer. In this way it plays the role for Unix/X11 that WinVNC plays for Windows.
{{Article summary end}}
+
 
 +
{{Note|x11vnc is not the only way to accomplish a remote control of the real X display; x0vncserver is part of {{pkg|tigervnc}} and allows for the same operation.}}
  
 
== Setting up x11vnc ==
 
== Setting up x11vnc ==
 +
 
=== Installation ===
 
=== Installation ===
{{pkg|x11vnc}} is available in the [[Official Repositories|official repositories]].
+
 
 +
{{Pkg|x11vnc}} is available in the [[official repositories]].
  
 
=== Starting ===
 
=== Starting ===
First, start X either by '''startx''' or through a manager such as [[GDM]] or [[SLiM]]. Then, open a terminal and type
+
 
 +
First, start X either by ''startx'' or through a manager such as [[GDM]] or [[SLiM]]. You may need to set up X to [[Headless With X|run headless]] too.  Then, open a terminal and type
 
  $ x11vnc -display :0
 
  $ x11vnc -display :0
  
Line 19: Line 24:
  
 
  #!/bin/bash
 
  #!/bin/bash
  /usr/bin/x11vnc -nap -wait 50 -noxdamage -passwd PASSWORD -display :0 -forever -o /var/log/x11vnc.log -bg
+
  x11vnc -nap -wait 50 -noxdamage -passwd PASSWORD -display :0 -forever -o /var/log/x11vnc.log -bg
  
{{Note|The password "PASSWORD" above is not secured; anyone who can run {{ic|ps}} on the machine will see it. Also note that {{ic|/var/log/x11vnc.log}} needs to be created manually and its ownership needs to match that of the user who will run it.}}
+
{{Note|The password "PASSWORD" above is not secured; anyone who can run {{ic|ps}} on the machine will see it. Also note that {{ic|/var/log/x11vnc.log}} needs to be created manually and its ownership needs to match that of the user who will run it.}}
  
 
==== Setting X authority ====
 
==== Setting X authority ====
You may set an X authority file for the VNC server. This is accomplished by using the {{ic|-auth}} argument followed by the appropriate file, which will depend on how your X server was started. Generally, assigning an X authority file requires running x11vnc as root.
+
 
 +
You may set an X authority file for the VNC server. This is accomplished by using the {{ic|-auth}} argument followed by the appropriate file, which will depend on how your X server was started. Generally, assigning an X authority file requires running ''x11vnc'' as root.
  
 
===== Start X =====
 
===== Start X =====
Line 30: Line 36:
 
  $ x11vnc -display :0 -auth ~/.Xauthority
 
  $ x11vnc -display :0 -auth ~/.Xauthority
 
If that fails, you may have to run (as root)
 
If that fails, you may have to run (as root)
  $ x11vnc -display :0 -auth /home/USER/.Xauthority
+
  # x11vnc -display :0 -auth /home/''user''/.Xauthority
Where USER is the username of the user who is running the X server.
+
Where ''user'' is the username of the user who is running the X server.
  
 
===== GDM =====
 
===== GDM =====
 +
 +
{{Note|Newer GDM packages ship with Xwayland as the default display server backend. The following instructions, however, only apply when using Xorg (else {{ic|.Xauthority}} is not created, and ''x11vnc'' fails to start). You are therefore advised to uncomment {{ic|<nowiki>#WaylandEnable=false</nowiki>}} setting in {{ic|/etc/gdm/custom.conf}} in order to proceed.}}
  
 
  # x11vnc -display :0 -auth /var/lib/gdm/:0.Xauth
 
  # x11vnc -display :0 -auth /var/lib/gdm/:0.Xauth
  
OR
+
Newer versions of GDM uses /run/user. Example for user 120 (gdm), used for login screen.
see [[#Troubleshooting|Troubleshooting]] section below
+
 
 +
# x11vnc -display :0 -auth /run/user/120/gdm/Xauthority
 +
 
 +
or see [[#Troubleshooting|Troubleshooting]] section below
  
 
===== SLIM =====
 
===== SLIM =====
Line 62: Line 73:
  
 
==== Running constantly ====
 
==== Running constantly ====
 +
 
By default, x11vnc will accept the first VNC session and shutdown when the session disconnects.
 
By default, x11vnc will accept the first VNC session and shutdown when the session disconnects.
 
In order to avoid that, start x11vnc with the '''-many''' or '''-forever''' argument, like this:
 
In order to avoid that, start x11vnc with the '''-many''' or '''-forever''' argument, like this:
Line 69: Line 81:
  
 
=== Accessing ===
 
=== Accessing ===
 +
 
Get a VNC client on another computer, and type in the IP address of the computer running x11vnc. Hit connect, and you should be set.
 
Get a VNC client on another computer, and type in the IP address of the computer running x11vnc. Hit connect, and you should be set.
  
Line 74: Line 87:
  
 
== SSH Tunnel ==
 
== SSH Tunnel ==
 +
 
You need to have [[SSH]] installed and configured.
 
You need to have [[SSH]] installed and configured.
  
Use the -localhost flag to x11vnc to have it bind to the local interface. Once that is done, you can use SSH to tunnel the port, and then connect to VNC through SSH. (I have not tried this)
+
Use the {{ic|-localhost}} flag with x11vnc for it to bind to the local interface. Once that is done, you can use SSH to tunnel the port; then, connect to VNC through SSH.
''(confirmed working for me, thanks --bloodniece)''
+
  
 
Simple example (from http://www.karlrunge.com/x11vnc/index.html#tunnelling ):
 
Simple example (from http://www.karlrunge.com/x11vnc/index.html#tunnelling ):
Line 83: Line 96:
 
where USER is the username of the user who is running the X server.
 
where USER is the username of the user who is running the X server.
  
(you will likely have to provide passwords/passphrases to login from your current location into your remote_host Unix account; we assume you have a login account on remote_host and it is running the SSH server)
+
(You will likely have to provide passwords/passphrases to login from your current location into your remote_host Unix account; we assume you have a login account on remote_host and it is running the SSH server)
  
 
And then in another terminal window on your current machine run the command:
 
And then in another terminal window on your current machine run the command:
Line 90: Line 103:
  
 
== Troubleshooting ==
 
== Troubleshooting ==
 +
 
1. You can check your ip address and make sure port 5900 is forwarded by visiting [http://www.realvnc.com/cgi-bin/nettest.cgi this] website.
 
1. You can check your ip address and make sure port 5900 is forwarded by visiting [http://www.realvnc.com/cgi-bin/nettest.cgi this] website.
  
Line 100: Line 114:
 
If that does not exist, You can create one easily (Actually a symlink to actual one) by running command given below as normal user NOT ROOT OR USING [[Sudo]] as below:
 
If that does not exist, You can create one easily (Actually a symlink to actual one) by running command given below as normal user NOT ROOT OR USING [[Sudo]] as below:
  
  $ ln -sv `dirname $(xauth info | awk '/Authority file/{print $3}')` /home/`whoami`/.Xauthority
+
  $ ln -sv $(dirname $(xauth info | awk '/Authority file/{print $3}')) ~/.Xauthority
  
 
then try above [[#SSH Tunnel|tunneling]] example and it should work fine.
 
then try above [[#SSH Tunnel|tunneling]] example and it should work fine.
 
Further if you want this to be automatically done each time [[Xorg]] is restarted, create the [[Xprofile]] file & make is executable as below
 
Further if you want this to be automatically done each time [[Xorg]] is restarted, create the [[Xprofile]] file & make is executable as below
  
  $ ln -sf `dirname $(xauth info | awk '/Authority file/{print $3}')` /home/[ENTER_USERNAME_HERE]/.Xauthority
+
  $ ln -sf $(dirname $(xauth info | awk '/Authority file/{print $3}')) ~/.Xauthority
  
 
3.''' GNOME 3''' and '''x11vnc'''
 
3.''' GNOME 3''' and '''x11vnc'''
Line 111: Line 125:
 
If you are using GNOME 3 and x11vnc and you get the following errors
 
If you are using GNOME 3 and x11vnc and you get the following errors
  
<pre>*** XOpenDisplay failed (:0)  
+
*** XOpenDisplay failed (:0)  
 
+
*** x11vnc was unable to open the X DISPLAY: ":0", it cannot continue.</pre>
+
*** x11vnc was unable to open the X DISPLAY: ":0", it cannot continue.
  
 
Try running x11vnc like
 
Try running x11vnc like
  
  $ x11vnc -noxdamage -many -display :0 -auth /var/run/gdm/`sudo ls /var/run/gdm | grep \`whoami\``/database -forever -bg
+
  $ x11vnc -noxdamage -many -display :0 -auth /var/run/gdm/$(sudo ls /var/run/gdm | grep $(whoami))/database -forever -bg
  
Please update if this works / not works for any other [[Display Manager|display manager]] or [[Desktop Environment|desktop environment]].
+
Please update if this works / not works for any other [[display manager]] or [[desktop environment]].
  
 
4. Screensaver problem
 
4. Screensaver problem
  
 
If screensaver starts every 1-2 second, start x11vnc with -nodpms key.
 
If screensaver starts every 1-2 second, start x11vnc with -nodpms key.

Latest revision as of 20:15, 6 May 2016

Related articles

x11vnc allows one to view remotely and interact with real X displays (i.e. a display corresponding to a physical monitor, keyboard, and mouse) with any VNC viewer. In this way it plays the role for Unix/X11 that WinVNC plays for Windows.

Note: x11vnc is not the only way to accomplish a remote control of the real X display; x0vncserver is part of tigervnc and allows for the same operation.

Setting up x11vnc

Installation

x11vnc is available in the official repositories.

Starting

First, start X either by startx or through a manager such as GDM or SLiM. You may need to set up X to run headless too. Then, open a terminal and type

$ x11vnc -display :0

Another option is to place the x11vnc line in a script which is called at login.

#!/bin/bash
x11vnc -nap -wait 50 -noxdamage -passwd PASSWORD -display :0 -forever -o /var/log/x11vnc.log -bg
Note: The password "PASSWORD" above is not secured; anyone who can run ps on the machine will see it. Also note that /var/log/x11vnc.log needs to be created manually and its ownership needs to match that of the user who will run it.

Setting X authority

You may set an X authority file for the VNC server. This is accomplished by using the -auth argument followed by the appropriate file, which will depend on how your X server was started. Generally, assigning an X authority file requires running x11vnc as root.

Start X
$ x11vnc -display :0 -auth ~/.Xauthority

If that fails, you may have to run (as root)

# x11vnc -display :0 -auth /home/user/.Xauthority

Where user is the username of the user who is running the X server.

GDM
Note: Newer GDM packages ship with Xwayland as the default display server backend. The following instructions, however, only apply when using Xorg (else .Xauthority is not created, and x11vnc fails to start). You are therefore advised to uncomment #WaylandEnable=false setting in /etc/gdm/custom.conf in order to proceed.
# x11vnc -display :0 -auth /var/lib/gdm/:0.Xauth

Newer versions of GDM uses /run/user. Example for user 120 (gdm), used for login screen.

# x11vnc -display :0 -auth /run/user/120/gdm/Xauthority

or see Troubleshooting section below

SLIM
# x11vnc -display :0 -auth /var/run/slim.auth
Warning: This will set up VNC with NO PASSWORD. This means that ANYBODY who has access to the network the computer is on CAN SEE YOUR XSERVER. It is a fairly simple matter to tunnel your VNC connection through SSH to avoid this. Or, simply set a password, as described below.
Note: The password will only encrypt the login process itself. The transmission is still unencrypted[1].
LXDM
# x11vnc -display :0 -auth /var/run/lxdm/lxdm-\:0.auth

Setting a password

$ mkdir ~/.x11vnc
$ x11vnc -storepasswd password ~/.x11vnc/passwd

To connect using the stored password use the -rfbauth argument and point to the passwd file you created, like so:

$ x11vnc -display :0 -rfbauth ~/.x11vnc/passwd 

Your viewer should prompt for a password when connecting.

Running constantly

By default, x11vnc will accept the first VNC session and shutdown when the session disconnects. In order to avoid that, start x11vnc with the -many or -forever argument, like this:

$ x11vnc -many -display :0

or

$ x11vnc -forever -display :0

Accessing

Get a VNC client on another computer, and type in the IP address of the computer running x11vnc. Hit connect, and you should be set.

If you are attempting to access a VNC server / computer (running x11vnc) from outside of its network then you will need to ensure that it has port 5900 forwarded.

SSH Tunnel

You need to have SSH installed and configured.

Use the -localhost flag with x11vnc for it to bind to the local interface. Once that is done, you can use SSH to tunnel the port; then, connect to VNC through SSH.

Simple example (from http://www.karlrunge.com/x11vnc/index.html#tunnelling ):

$ ssh -t -L 5900:localhost:5900 remote_host 'sudo x11vnc -display :0 -auth /home/USER/.Xauthority'

where USER is the username of the user who is running the X server.

(You will likely have to provide passwords/passphrases to login from your current location into your remote_host Unix account; we assume you have a login account on remote_host and it is running the SSH server)

And then in another terminal window on your current machine run the command:

$ vncviewer -encodings "copyrect tight zrle hextile" localhost:0

Troubleshooting

1. You can check your ip address and make sure port 5900 is forwarded by visiting this website.

Tango-inaccurate.pngThe factual accuracy of this article or section is disputed.Tango-inaccurate.png

Reason: please use the first argument of the template to provide a brief explanation. (Discuss in Talk:X11vnc#)

2. Tested only on GNOME + GDM

If you cannot start the tunnel, and get error like XOpenDisplay(":0") failed, Check if you have a ~/.Xauthority directory. If that does not exist, You can create one easily (Actually a symlink to actual one) by running command given below as normal user NOT ROOT OR USING Sudo as below:

$ ln -sv $(dirname $(xauth info | awk '/Authority file/{print $3}')) ~/.Xauthority

then try above tunneling example and it should work fine. Further if you want this to be automatically done each time Xorg is restarted, create the Xprofile file & make is executable as below

$ ln -sf $(dirname $(xauth info | awk '/Authority file/{print $3}')) ~/.Xauthority

3. GNOME 3 and x11vnc

If you are using GNOME 3 and x11vnc and you get the following errors

*** XOpenDisplay failed (:0) 

*** x11vnc was unable to open the X DISPLAY: ":0", it cannot continue.

Try running x11vnc like

$ x11vnc -noxdamage -many -display :0 -auth /var/run/gdm/$(sudo ls /var/run/gdm | grep $(whoami))/database -forever -bg

Please update if this works / not works for any other display manager or desktop environment.

4. Screensaver problem

If screensaver starts every 1-2 second, start x11vnc with -nodpms key.