Hey there! How’s it going? Today what we are going to do is remotely connect to a linux machine with a GUI. Better than ssh right? For that we’ll be using VNC.

So VNC?

Virtual Network Computing (VNC). VNC is a graphical desktop sharing system. It uses Remote Frame Buffer protocol (RFB) protocol for the communication. If you are curious about the operation,

“The VNC server is the program on the machine that shares its screen. The server passively allows the client to take control of it. The VNC client (or viewer) is the program that watches, controls, and interacts with the server. The client controls the server.” – Wikipedia

We are using x11vnc as the VNC tool. Package: x11vnc, VNC server to allow remote access to an existing X session. Below is the simplest way to get the job done. Let’s dive in. SSH should be configured before hand.

Note that step 1 and 2 are server side configurations where as step 3 and 4 are client slide.

Step 1

Install x11vnc on the remote machince(Server)

sudo apt-get install x11vnc

 

Step 2

Run the below command to start to sharing. Here Xauhority file is provided to Light DM

sudo x11vnc -auth /var/lib/lightdm/.Xauthority -display :0

 

If the command is successfully executed you should get the O/P shown in the Figure 1. If you want a bigger resolution set the resolution using geometry parameter as below.

sudo x11vnc -auth /var/lib/lightdm/.Xauthority -display :0 -geometry 1440x900

Step 3

Install the VNC client on the machince(Client)

sudo apt-get install vncviewer

 

Step 4

Connect from the remote machine(Client). The option -via is for using ssh.

vncviewer -via user@server_ip localhost:0

 

Below is the Figure 1

###############################################################
#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#
#@ @#
#@ ** 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. @#
#@ @#
#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#
###############################################################
05/11/2014 15:11:14 x11vnc version: 0.9.12 lastmod: 2010-09-09 pid: 8020
05/11/2014 15:11:14 Using X display :0
05/11/2014 15:11:14 rootwin: 0x150 reswin: 0x3a00001 dpy: 0x1e2e480
05/11/2014 15:11:14 
05/11/2014 15:11:14 ------------------ USEFUL INFORMATION ------------------
05/11/2014 15:11:14 X DAMAGE available on display, using it for polling hints.
05/11/2014 15:11:14 To disable this behavior use: '-noxdamage'
05/11/2014 15:11:14 
05/11/2014 15:11:14 Most compositing window managers like 'compiz' or 'beryl'
05/11/2014 15:11:14 cause X DAMAGE to fail, and so you may not see any screen
05/11/2014 15:11:14 updates via VNC. Either disable 'compiz' (recommended) or
05/11/2014 15:11:14 supply the x11vnc '-noxdamage' command line option.
05/11/2014 15:11:14 
05/11/2014 15:11:14 Wireframing: -wireframe mode is in effect for window moves.
05/11/2014 15:11:14 If this yields undesired behavior (poor response, painting
05/11/2014 15:11:14 errors, etc) it may be disabled:
05/11/2014 15:11:14 - use '-nowf' to disable wireframing completely.
05/11/2014 15:11:14 - use '-nowcr' to disable the Copy Rectangle after the
05/11/2014 15:11:14 moved window is released in the new position.
05/11/2014 15:11:14 Also see the -help entry for tuning parameters.
05/11/2014 15:11:14 You can press 3 Alt_L's (Left "Alt" key) in a row to 
05/11/2014 15:11:14 repaint the screen, also see the -fixscreen option for
05/11/2014 15:11:14 periodic repaints.
05/11/2014 15:11:14 
05/11/2014 15:11:14 XFIXES available on display, resetting cursor mode
05/11/2014 15:11:14 to: '-cursor most'.
05/11/2014 15:11:14 to disable this behavior use: '-cursor arrow'
05/11/2014 15:11:14 or '-noxfixes'.
05/11/2014 15:11:14 using XFIXES for cursor drawing.
05/11/2014 15:11:14 GrabServer control via XTEST.
05/11/2014 15:11:14 
05/11/2014 15:11:14 Scroll Detection: -scrollcopyrect mode is in effect to
05/11/2014 15:11:14 use RECORD extension to try to detect scrolling windows
05/11/2014 15:11:14 (induced by either user keystroke or mouse input).
05/11/2014 15:11:14 If this yields undesired behavior (poor response, painting
05/11/2014 15:11:14 errors, etc) it may be disabled via: '-noscr'
05/11/2014 15:11:14 Also see the -help entry for tuning parameters.
05/11/2014 15:11:14 You can press 3 Alt_L's (Left "Alt" key) in a row to 
05/11/2014 15:11:14 repaint the screen, also see the -fixscreen option for
05/11/2014 15:11:14 periodic repaints.
05/11/2014 15:11:14 
05/11/2014 15:11:14 XKEYBOARD: number of keysyms per keycode 7 is greater
05/11/2014 15:11:14 than 4 and 51 keysyms are mapped above 4.
05/11/2014 15:11:14 Automatically switching to -xkb mode.
05/11/2014 15:11:14 If this makes the key mapping worse you can
05/11/2014 15:11:14 disable it with the "-noxkb" option.
05/11/2014 15:11:14 Also, remember "-remap DEAD" for accenting characters.
05/11/2014 15:11:14 
05/11/2014 15:11:14 X FBPM extension not supported.
05/11/2014 15:11:14 X display is capable of DPMS.
05/11/2014 15:11:14 --------------------------------------------------------
05/11/2014 15:11:14 
05/11/2014 15:11:14 Default visual ID: 0x21
05/11/2014 15:11:14 Read initial data from X display into framebuffer.
05/11/2014 15:11:14 initialize_screen: fb_depth/fb_bpp/fb_Bpl 24/32/3200
05/11/2014 15:11:14 
05/11/2014 15:11:14 X display :0 is 32bpp depth=24 true color
05/11/2014 15:11:14 
05/11/2014 15:11:14 Autoprobing TCP port 
05/11/2014 15:11:14 Autoprobing selected port 5900
05/11/2014 15:11:14 Listening also on IPv6 port 5900 (socket 10)
05/11/2014 15:11:14 
05/11/2014 15:11:14 Xinerama is present and active (e.g. multi-head).
05/11/2014 15:11:14 Xinerama: number of sub-screens: 1
05/11/2014 15:11:14 Xinerama: no blackouts needed (only one sub-screen)
05/11/2014 15:11:14 
05/11/2014 15:11:14 fb read rate: 1594 MB/sec
05/11/2014 15:11:14 fast read: reset wait ms to: 10
05/11/2014 15:11:14 fast read: reset defer ms to: 10
05/11/2014 15:11:14 The X server says there are 10 mouse buttons.
05/11/2014 15:11:14 screen setup finished.
05/11/2014 15:11:14 
05/11/2014 15:11:14 WARNING: You are running x11vnc WITHOUT a password. See
05/11/2014 15:11:14 WARNING: the warning message printed above for more info.
05/11/2014 15:11:14
The VNC desktop is: ubuntu:0
PORT=5900
******************************************************************************
Have you tried the x11vnc '-ncache' VNC client-side pixel caching feature yet?
The scheme stores pixel data offscreen on the VNC viewer side for faster
retrieval. It should work with any VNC viewer. Try it by running:
x11vnc -ncache 10 ...
One can also add -ncache_cr for smooth 'copyrect' window motion.
More info: http://www.karlrunge.com/x11vnc/faq.html#faq-client-caching

This is one of the most easiest way to connect to a remote machine with a GUI in a Linux environment. There is a lot more to be done. As an example you could set up a password for the connection to make it more secure.

Troubleshooting

You might get a error like below if you try below.

No protocol specified
20/03/2015 09:26:08 XOpenDisplay(":0") failed.
20/03/2015 09:26:08 Trying again with XAUTHLOCALHOSTNAME=localhost ...
No protocol specified

Try executing below command.

root@server:/opt# ps wwaux | grep auth
root 1242 0.2 0.5 207340 48608 tty7 Ssl+ Mar19 2:02 /usr/bin/X :0 -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -novtswitch -background none
vnc 1308 0.0 0.0 15548 3660 ? S Mar19 0:00 Xtightvnc :1 -desktop X -auth /home/vnc/.Xauthority -geometry 1024x768 -depth 16 -rfbwait 120000 -rfbauth /home/vnc/.vnc/passwd -rfbport 5901 -fp /usr/share/fonts/X11/misc/,/usr/share/fonts/X11/Type1/,/usr/share/fonts/X11/75dpi/,/usr/share/fonts/X11/100dpi/ -co /etc/X11/rgb
1000 3391 0.0 0.1 302224 8560 ? Sl 09:12 0:00 /usr/lib/policykit-1-gnome/polkit-gnome-authentication-agent-1
root 5587 0.0 0.0 8108 944 pts/1 S+ 09:31 0:00 grep --color=auto auth

reaplce -auth parameter with the given O/P as below

x11vnc -auth /var/run/lightdm/root/:0 -display :0

That’s it.

Hope you got an idea about how to remotely login with a GUI in Linux. If you have any questions let me know in the comments below. Your feedback is highly appreciated(happy-face).

Loading

2 Comments

  1. tacos December 14, 2014 at 5:47 am

    needed to do this on the remote machine… gsettings set org.gnome.Vino require-encryption false …to get it to work. going to go back in tomorrow and add passwords n such. i was having all kinds of issues, though. thanks.

    Reply

Leave A Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.