Copy and paste over VNC between local and remote desktop

Posted on Mon 12 November 2018 in article

Here I would like to describe how to achieve copy paste capability for VNC connection between remote and local computer. With such capability working between two computers and sharing clipboard would became much more enjoyable.

My configuration is as follows:

  • Local computer: Windows 10, VNC viewer 6
  • Remote computer: VM on GCP, Debian 9, VNC server: tigerVNC

Here I assume that there you already have working VNC connection between local and remote computer. In my previous post I described how to establish such connection here.

First make sure than copy-past option is switched on on your local VNC viewer (File/Preferences/Privacy/ Allow copy and paste to and from VNC server).

Then, you must turn off vncserver on your remote. This can be done by executing following code:

vncserver -kill :*
or vncserver -kill :<number of your desktop>

Now open terminal, and download autocutset package:

sudo apt install autocutsel

Then we need to edit our VNC startup script. With your favorite text editor edit file "/home/ptwnuk/.vnc/xstartup":

nano /home/ptwnuk/.vnc/xstartup

Change it accordingly:

#!/bin/sh

# Uncomment the following two lines for normal desktop:
# unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
#xsetroot -solid grey
autocutsel -fork  
vncconfig -iconic &
vncconfig -nowin &
x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
x-window-manager &
startxfce4 &
#gnome-panel &
#gnome-settings-daemon &
#metacity &
#nautilus &

Now you can start VNC server one more time:

vncserver

After those steps you should have both way copy paste capabilities between your local and remote machine.