How to Have a true Remote Desktop on Linux / Fedora 25 VNC

Remote Desktop Icon

Loading

Remote Desktop on Linux with VNC

 

 

 

There are different ways to have remote desktops on linux. 

I did not want separate VNC sessions, I wanted a true / shared desktop. I needed a way to show whatever is on my screens to the  client.

I also wanted it to start on boot with no intervention, and restart if it dies, so that no matter where I am I can always connect to my desktop.

I have done this with multiple Fedora versions, and it will likely work on other distros maybe with a little tweaks.

Depending on what display manager you use, and what distro you use, this may not work out of the box. 

This will work out of the box on Fedora 25 with LightDM, KDM, GDM, XDM, and SDDM. 

It will work on older Fedora versions using LightDM and SDDM, but might require some tweaks for other display managers.

If you need help getting it to work for your Distro just ask, and if you have a better way to do this, please comment!

 

  1. Install x11vnc and tigervnc-server
  2. Create a systemd service file to start on boot
  3. Create x11vnc startup script
  4. Create x11vnc password file
  5. Enable service

 

Step 1: Install x11vnc and tigervnc-server

sudo dnf install x11vnc tigervnc-server

 

Step 2: Create a systemd service file to start on boot

Create a file : /usr/lib/systemd/system/x11vnc.service and put the following :

[Unit]
Description=X11vnc
After=graphical.target

[Service]
Type=forking
ExecStart=/root/X11vnc_init
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=X11VNC
SyslogFacility=local5
SyslogLevel=debug
[Install]
WantedBy=graphical.target

Step 3: Create a x11vnc startup script

Create a file : /root/X11vnc_init and put the following :

#!/usr/bin/perl

if($ARGV[0] eq "stop"){system("killall -9 x11vnc"); exit 0;}
$DM="";
$LIGHT=`pgrep -x lightdm`; chomp $LIGHT;
if($LIGHT){
$DM="lightdm";
print "Found Lightdm Display manager\n";
goto nextstep;
}
$KDM=`pgrep -x kdm`; chomp $KDM;
if($KDM){
$DM="kdm";
print "Found KDM Display manager\n";
goto nextstep;
}
$GDM=`pgrep -x gdm`; chomp $GDM;
if($GDM){
$DM="gdm";
$dm=`ps ax |grep gdm |grep \\\\-auth |grep -v grep`;chomp $dm;
($junk1,$junk2)=split(/-auth /,$dm);
($junk3,$junk4)=split(/\/gdm\/Xauthority /,$junk2);
$authfile="$junk3/gdm/Xauthority";
print "Found GDM Display manager with authfile $authfile\n";
goto nextstep;
}
$XDM=`pgrep -x xdm`; chomp $XDM;
if($XDM){
$dm=`ps ax |grep xdm |grep authdir |grep -v grep`; chomp $dm;
($a,$filename)=split(/authdir\/authfiles\//,$dm);
$authfile="/var/lib/xdm/authdir/authfiles/$filename";
$DM="xdm";
print "Found XDM Display manager with authfile $authfile\n";
goto nextstep;
}
$SDDM=`pgrep -x sddm`; chomp $SDDM;
if($SDDM){
$dm=`ps ax |grep sddm |grep var/run |grep -v grep`; chomp $dm;
($junk1,$junk2)=split(/-background/,$dm);
($junk3,$junk4)=split(/var\/run\/sddm\//,$junk1);
$filename="/var/run/sddm/$junk4";
$authfile="$filename";
$DM="sddm";
print "Found SDDM Display manager with authfile $authfile\n";
goto nextstep;
}
nextstep:
if($DM eq "gdm"){$AUTH="-auth $authfile";}
if($DM eq "lightdm"){ $AUTH="-auth /var/run/lightdm/root/:0 ";}
if($DM eq "kdm" ){ $AUTH="-auth guess ";}
if($DM eq "xdm" || $DM eq "sddm"){$AUTH="-auth $authfile ";}
if(!$DM){
print "NO Compatible dm found\n";
exit 0;
}
my $pid = fork();
$XCMD="/usr/bin/x11vnc \
-rfbauth /root/x11vncpasswd \
-nap -many -norepeat 5 -alwaysshared -dontdisconnect \
-shared -nolookup \
$AUTH \
-rfbport 5900 -no6 -xkb -display :0 &";
$XCMD=~s/\n/ /gm;
open tmpsh,">/tmp/tmpvnc.sh";
print tmpsh "#!/bin/bash
sleep 10;
$XCMD
";
close tmpsh;
system("chmod 755 /tmp/tmpvnc.sh");
system("/tmp/tmpvnc.sh &");
exit 0;

Step 4 : Create a VNC Password file

Run the command : vncpasswd /root/x11vncpasswd

Type and Verify the password you want your client to use to connect to the desktop.

Step 5: Enable the service and reboot

systemctl enable x11vnc

 

Now you can either run: systemctl start x11vnc and the service should start, or you can reboot to make sure it works right.

When your having problems and x11vnc is not running , run the script from the shell so you can see the output. : /root/X11vnc_init

If you still cant get it to work, leave a comment or email me on facebook and I will help you out. 

Related posts

10 thoughts on “How to Have a true Remote Desktop on Linux / Fedora 25 VNC

  1. tadalafil 20 mg

    Amazing lots of amazing information.

  2. cialis generico online http://vioglichfu.7m.pl/

    Incredible a good deal of valuable information.

  3. I’m getting “x11vnc.service: Failed at step EXEC spawning /root/X11vnc_init: Permission denied”, even after trying “chmod 777” that file?

  4. I’m getting the following (per journal -xe)
    “x11vnc.service: Failed at step EXEC spawning /root/X11vnc_init: Permission denied”

    I tried simply chmod 777 that file, but still no luck?

  5. Hello Ryan,

    your tutorial looks amazing, i followed all mentioned steps, but after x11vnc service i got an error message:
    [root@FedoraLXQT ~]# systemctl status x11vnc.service
    ● x11vnc.service – X11vnc
    Loaded: loaded (/usr/lib/systemd/system/x11vnc.service; enabled; vendor preset: disabled)
    Active: failed (Result: exit-code) since Wed 2017-07-19 21:11:06 CEST; 7s ago
    Process: 11574 ExecStart=/root/X11vnc_init (code=exited, status=203/EXEC)

    Jul 19 21:11:06 FedoraLXQT systemd[1]: x11vnc.service: Unit entered failed state.
    Jul 19 21:11:06 FedoraLXQT systemd[1]: x11vnc.service: Failed with result ‘exit-code’.
    Jul 19 21:11:06 FedoraLXQT systemd[1]: x11vnc.service: Service hold-off time over, scheduling restart.
    Jul 19 21:11:06 FedoraLXQT systemd[1]: Stopped X11vnc.
    Jul 19 21:11:06 FedoraLXQT systemd[1]: x11vnc.service: Start request repeated too quickly.
    Jul 19 21:11:06 FedoraLXQT systemd[1]: Failed to start X11vnc.
    Jul 19 21:11:06 FedoraLXQT systemd[1]: x11vnc.service: Unit entered failed state.
    Jul 19 21:11:06 FedoraLXQT systemd[1]: x11vnc.service: Failed with result ‘exit-code’.
    [root@FedoraLXQT ~]# journalctl -xe
    — Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel

    — The process /root/X11vnc_init could not be executed and failed.

    — The error number returned by this process is 13.
    Jul 19 21:11:06 FedoraLXQT systemd[1]: x11vnc.service: Control process exited, code=exited status=203
    Jul 19 21:11:06 FedoraLXQT systemd[1]: Failed to start X11vnc.
    — Subject: Unit x11vnc.service has failed
    — Defined-By: systemd
    — Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel

    — Unit x11vnc.service has failed.

    — The result is failed.
    Jul 19 21:11:06 FedoraLXQT audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s
    Jul 19 21:11:06 FedoraLXQT systemd[1]: x11vnc.service: Unit entered failed state.
    Jul 19 21:11:06 FedoraLXQT systemd[1]: x11vnc.service: Failed with result ‘exit-code’.
    Jul 19 21:11:06 FedoraLXQT systemd[1]: x11vnc.service: Service hold-off time over, scheduling restart.
    Jul 19 21:11:06 FedoraLXQT systemd[1]: Stopped X11vnc.
    — Subject: Unit x11vnc.service has finished shutting down
    — Defined-By: systemd
    — Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel

    — Unit x11vnc.service has finished shutting down.
    Jul 19 21:11:06 FedoraLXQT audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s
    Jul 19 21:11:06 FedoraLXQT audit[1]: SERVICE_STOP pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0
    Jul 19 21:11:06 FedoraLXQT systemd[1]: x11vnc.service: Start request repeated too quickly.
    Jul 19 21:11:06 FedoraLXQT systemd[1]: Failed to start X11vnc.
    — Subject: Unit x11vnc.service has failed
    — Defined-By: systemd
    — Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel

    Can you help me how to make it work?

    Thank you

  6. Hi i just discovery your blog, its very good, i have similar error on start x11vnc service, i execute the script and get this help please, and many thanks for your help and time.

    ./X11vnc_init
    Found GDM Display manager with authfile /gdm/Xauthority
    [13:45 root@inventory ~]# 11/07/2017 13:46:09 11/07/2017 13:46:09 passing arg to libvncserver: -rfbauth
    passing arg to libvncserver: -rfbauth
    11/07/2017 13:46:09 11/07/2017 13:46:09 passing arg to libvncserver: /root/x11vncpasswd
    passing arg to libvncserver: /root/x11vncpasswd
    11/07/2017 13:46:09 11/07/2017 13:46:09 passing arg to libvncserver: -alwaysshared
    passing arg to libvncserver: -alwaysshared
    11/07/2017 13:46:09 passing arg to libvncserver: -dontdisconnect
    11/07/2017 13:46:09 passing arg to libvncserver: -dontdisconnect
    11/07/2017 13:46:09 passing arg to libvncserver: -rfbport
    11/07/2017 13:46:09 passing arg to libvncserver: -rfbport
    11/07/2017 13:46:09 passing arg to libvncserver: 5900
    11/07/2017 13:46:09 passing arg to libvncserver: 5900
    11/07/2017 13:46:09 11/07/2017 13:46:09 x11vnc version: 0.9.14 lastmod: 2013-11-21 pid: 17254
    x11vnc version: 0.9.14 lastmod: 2013-11-21 pid: 17253
    No protocol specified
    11/07/2017 13:46:09 XOpenDisplay(“:0”) failed.
    11/07/2017 13:46:09 Trying again with XAUTHLOCALHOSTNAME=localhost …
    No protocol specified
    11/07/2017 13:46:09 XOpenDisplay(“:0”) failed.
    11/07/2017 13:46:09 Trying again with XAUTHLOCALHOSTNAME=localhost …
    No protocol specified

    11/07/2017 13:46:09 ***************************************
    11/07/2017 13:46:09 *** 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.

  7. systemctl start x11vnc gives me a failure message, so when I ran /root/X11vnc_init I got:
    XOpenDisplay failed (:0)
    thanks for any pointers

  8. This works fantastic for me; thanks! However, why do we need to install both x11vnc and tigervnc-server? Is this necessary to get around the issue with Wayland?

  9. Hi Ryan,
    I am having trouble setting up x11vnc. I am getting error enabling service.
    systemctl enable x11vnc
    Failed to enable unit: Invalid argument

    Thanks.

    1. Run the script as root from the commands line and see the output /root/X11vnc_init

Leave a Comment