united states of america usa  linkedinfacebook   Call Us Today: (315) 646-4455

Setup VNC in Ubuntu

vnc iconYou have a server, but want to setup VNC to access the GUI? We use this tutorial for our systems and wanted to share. (ALT is an IT consulting company, offering technical support for Mac, PC and Linux systems). We try to keep things updated, but tutorials have a tendency of exiring, so some steps may be different for newer versions. We've used Ubuntu 16.04 to install, but it should work with others as well.

Install the components

apt-get -y install ubuntu-desktop tightvncserver xfce4 xfce4-goodies autocutsel

Add the vnc user and give it a password:

adduser vnc
passwd vnc

You can add vnc as sudo, so you could run apps as root. Edit the sudoers file:

echo "vnc ALL=(ALL)       ALL" >> /etc/sudoers

Now setup the vnc password using vnspasswd (make it the same as the user pass for the sake of simplicity):

su - vnc

Next, let's install VNC as a service. Login as root and edit /etc/init.d/vncserver. Copy paste the following:

export USER="vnc"
OPTIONS="-depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY}"
. /lib/lsb/init-functions

case "$1" in
log_action_begin_msg "Starting vncserver for user '${USER}' on localhost:${DISPLAY}"
su ${USER} -c "/usr/bin/vncserver ${OPTIONS}"

log_action_begin_msg "Stoping vncserver for user '${USER}' on localhost:${DISPLAY}"
su ${USER} -c "/usr/bin/vncserver -kill :${DISPLAY}"

$0 stop
$0 start
exit 0

Edit /home/vnc/.vnc/xstartup and copy/paste the following:

xrdb $HOME/.Xresources
xsetroot -solid grey
autocutsel -s PRIMARY -fork
startxfce4 &

Finally, update file permissions and allow users to start the X Server

chown -R vnc. /home/vnc/.vnc && chmod +x /home/vnc/.vnc/xstartup
sed -i 's/allowed_users.*/allowed_users=anybody/g' /etc/X11/Xwrapper.config

Make /etc/init.d/vncserver executable, add the VNC service and start it:

chmod +x /etc/init.d/vncserver
update-rc.d vncserver defaults
service vncserver start

You are done. You can access the server using any of the VNC clients. We use TightVNC.

The copy paste from Windows to Linux doesn't seem to work (it works from Linux to Windows). If you find a way to make it work, drop us a line.

Tab is not working in VNC

Tab doesn't seem to work in XFCE. To solve this, edit the following file:

vim /home/vnc/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml

Find this line:

<property name="&lt;Super&gt;Tab" type="string" value="switch_window_key"/>

and replace with:

<property name="&lt;Super&gt;Tab" type="empty"/>

Tab should work as usual.

 Original article posted on ALT Technical Miami.

Last updated Feb 18, 2024