3

I'm on an Ubuntu system which has a touchscreen set up on display :0. I wanted to be able to control this touchscreen remotely from Windows, so I set up x11vnc. It works great. But here's the setup:

I have two users (excluding root). One restricted user (basically no permissions, and no password) who logs in automatically to the touchscreen, and one fully configured user with a complex password, sudo permission, etc. I only really care about starting x11vnc when the restricted user logs in (touchscreen becomes active), so I put the command x11vnc -loop & at the end of the file /home/restricted/.profile. Works fine. Note, however, that it has to be a background process because there's other commands that this user has to run (hidden from the human user) later on.

The problem I'm having is that x11vnc is very noisy with its output. Especially if you don't use a password (which I don't), and it's a loop so it just keeps on repeating. Usually this wouldn't be an issue, but not only is redirecting the output to /dev/null not working (explained below), but the output is appearing on the other user's terminal when I log in via ssh to it (which is really annoying because I use that account for maintenance and its impossible to do anything when your screen is being filled with output of some background process. Here's an example of the output I get:

--- x11vnc loop: 1 ---

--- x11vnc loop: waiting for: 1551

###############################################################
#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#
#@                                                           @#
#@  **  WARNING  **  WARNING  **  WARNING  **  WARNING  **   @#
#@                                                           @#
#@        YOU ARE RUNNING X11VNC WITHOUT A PASSWORD!!        @#
#@                                                           @#
#@  This means anyone with network access to this computer   @#
#@  may be able to view and control your desktop.            @#
#@                                                           @#
#@ >>> If you did not mean to do this Press CTRL-C now!! <<< @#
#@                                                           @#
#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#
#@                                                           @#
#@  You can create an x11vnc password file by running:       @#
#@                                                           @#
#@       x11vnc -storepasswd password /path/to/passfile      @#
#@  or   x11vnc -storepasswd /path/to/passfile               @#
#@  or   x11vnc -storepasswd                                 @#
#@                                                           @#
#@  (the last one will use ~/.vnc/passwd)                    @#
#@                                                           @#
#@  and then starting x11vnc via:                            @#
#@                                                           @#
#@      x11vnc -rfbauth /path/to/passfile                    @#
#@                                                           @#
#@  an existing ~/.vnc/passwd file from another VNC          @#
#@  application will work fine too.                          @#
#@                                                           @#
#@  You can also use the -passwdfile or -passwd options.     @#
#@  (note -passwd is unsafe if local users are not trusted)  @#
#@                                                           @#
#@  Make sure any -rfbauth and -passwdfile password files    @#
#@  cannot be read by untrusted users.                       @#
#@                                                           @#
#@  Use x11vnc -usepw to automatically use your              @#
#@  ~/.vnc/passwd or ~/.vnc/passwdfile password files.       @#
#@  (and prompt you to create ~/.vnc/passwd if neither       @#
#@  file exists.)  Under -usepw, x11vnc will exit if it      @#
#@  cannot find a password to use.                           @#
#@                                                           @#
#@                                                           @#
#@  Even with a password, the subsequent VNC traffic is      @#
#@  sent in the clear.  Consider tunnelling via ssh(1):      @#
#@                                                           @#
#@    http://www.karlrunge.com/x11vnc/#tunnelling            @#
#@                                                           @#
#@  Or using the x11vnc SSL options: -ssl and -stunnel       @#
#@                                                           @#
#@  Please Read the documention for more info about          @#
#@  passwords, security, and encryption.                     @#
#@                                                           @#
#@    http://www.karlrunge.com/x11vnc/faq.html#faq-passwd    @#
#@                                                           @#
#@  To disable this warning use the -nopw option, or put     @#
#@  'nopw' on a line in your ~/.x11vncrc file.               @#
#@                                                           @#
#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#
###############################################################
20/05/2016 10:53:18 x11vnc version: 0.9.13 lastmod: 2011-08-10  pid: 1551
20/05/2016 10:53:18 XOpenDisplay("") failed.
20/05/2016 10:53:18 Trying again with XAUTHLOCALHOSTNAME=localhost ...
20/05/2016 10:53:18
20/05/2016 10:53:18 *** XOpenDisplay failed. No -display or DISPLAY.
20/05/2016 10:53:18 *** Trying ":0" in 4 seconds.  Press Ctrl-C to abort.
20/05/2016 10:53:18 *** 1 2 3 4
Invalid MIT-MAGIC-COOKIE-1 key20/05/2016 10:53:22 XOpenDisplay(":0") failed.
20/05/2016 10:53:22 Trying again with XAUTHLOCALHOSTNAME=localhost ...
Invalid MIT-MAGIC-COOKIE-1 key20/05/2016 10:53:22 XOpenDisplay(":0") failed.
20/05/2016 10:53:22 Trying again with unset XAUTHLOCALHOSTNAME ...
Invalid MIT-MAGIC-COOKIE-1 key20/05/2016 10:53:22

20/05/2016 10:53:22 ***************************************
20/05/2016 10:53:22 *** XOpenDisplay failed (:0)

*** x11vnc was unable to open the X DISPLAY: ":0", it cannot continue.
*** There may be "Xlib:" error messages above with details about the failure.

Some tips and guidelines:

** An X server (the one you wish to view) must be running before x11vnc is
   started: x11vnc does not start the X server.  (however, see the -create
   option if that is what you really want).

** You must use -display <disp>, -OR- set and export your $DISPLAY
   environment variable to refer to the display of the desired X server.
 - Usually the display is simply ":0" (in fact x11vnc uses this if you forget
   to specify it), but in some multi-user situations it could be ":1", ":2",
   or even ":137".  Ask your administrator or a guru if you are having
   difficulty determining what your X DISPLAY is.

** Next, you need to have sufficient permissions (Xauthority)
   to connect to the X DISPLAY.   Here are some Tips:

 - Often, you just need to run x11vnc as the user logged into the X session.
   So make sure to be that user when you type x11vnc.
 - Being root is usually not enough because the incorrect MIT-MAGIC-COOKIE
   file may be accessed.  The cookie file contains the secret key that
   allows x11vnc to connect to the desired X DISPLAY.
 - You can explicitly indicate which MIT-MAGIC-COOKIE file should be used
   by the -auth option, e.g.:
       x11vnc -auth /home/someuser/.Xauthority -display :0
       x11vnc -auth /tmp/.gdmzndVlR -display :0
   you must have read permission for the auth file.
   See also '-auth guess' and '-findauth' discussed below.

** If NO ONE is logged into an X session yet, but there is a greeter login
   program like "gdm", "kdm", "xdm", or "dtlogin" running, you will need
   to find and use the raw display manager MIT-MAGIC-COOKIE file.
   Some examples for various display managers:

     gdm:     -auth /var/gdm/:0.Xauth
              -auth /var/lib/gdm/:0.Xauth
     kdm:     -auth /var/lib/kdm/A:0-crWk72
              -auth /var/run/xauth/A:0-crWk72
     xdm:     -auth /var/lib/xdm/authdir/authfiles/A:0-XQvaJk
     dtlogin: -auth /var/dt/A:0-UgaaXa

   Sometimes the command "ps wwwwaux | grep auth" can reveal the file location.

   Starting with x11vnc 0.9.9 you can have it try to guess by using:

              -auth guess

   (see also the x11vnc -findauth option.)

   Only root will have read permission for the file, and so x11vnc must be run
   as root (or copy it).  The random characters in the filenames will of course
   change and the directory the cookie file resides in is system dependent.

See also: http://www.karlrunge.com/x11vnc/faq.html

 --- x11vnc loop: sleeping 2000 ms ---


 --- x11vnc loop: 2 ---

And that just repeats on and on.

It's yelling at me about not being able to open the display, but it works. I'm guessing this is because the restricted user already ran this command and it connected fine, but now this user is trying to do so as well, so it can't connect.

Why is this happening? There's clearly some hole in my understanding. Here are the different things I tried:


Redirecting output to /dev/null

In the same place, /home/restricted/.profile I tried replacing the existing command x11vnc -loop & with x11vnc -loop > /dev/null 2>&1 &.

This had zero effect, output was still on other user's terminal and (obviously) didn't go away.


Running command with nohup

Again in /home/restricted/.profile, I tried replacing the existing command x11vnc -loop & with nohup x11vnc -loop &.

Once again, this had no effect at all. Output was still there. Nohup didn't even create a nohup.out file. At least, I couldn't find it.

For sake of completion, I also tried nohup x11vnc -loop > /dev/null 2>&1 & again, nothing changed.


Starting x11vnc as a daemon

Here, I started realizing that I was doing something wrong. I figured that maybe it was because /home/restricted/.profile was the wrong place to put this kind of thing. So I made a script in /etc/init.d to be run on boot and made the link with update-rc.d following the example of the skeleton file.

Once again, x11vnc worked, but the output was on all my terminals.


Starting x11vnc in screen

My last attempt at fixing this thing was throwing the command in a screen session. Screen usually fixes problems like this for me... But not this time.

In /home/restricted/.profile, I replaced x11vnc -loop & with screen -d -R x11vnc x11vnc -loop

This time, x11vnc didn't work anymore (wasn't able to connect via Windows client), but the output was STILL on all the terminals.


Again, clearly there's something I'm not understanding either about x11vnc or spawning a process on boot.

As you might have been able to tell from the above, I've been at this troubleshooting for a while and can't find anything else on the web about this. So help here would be awesome. Thanks in advance.

  • Maybe if you detach it from controlling tty, for example with setsid, it will calm down? Always wondered about x11vnc being such VERY noisy. However 0.9.3 which I am using is not noisy if I will just daemonize it. – user140866 May 20 '16 at 17:12
  • Your command x11vnc -loop & > /dev/null 2>&1 has the & in the wrong place. It must be at the end, as it is like a ; and ends a command. Also try -q and -o logfile for the output. – meuh May 20 '16 at 17:33
  • @meuh Whoops! You're right, my bad. I just fixed it and tried again, but it didn't resolve the problem. I will fix my code above so that others don't assume the same problem though. – MD-7 May 20 '16 at 17:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.