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

Remote Desktop Icon

6,549 total views, 6 views today

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

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

  1. 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