Tuesday, May 01, 2018

Remote Ubuntu dev setup with multi screen VNC

Goal: A VM in the cloud or similar running an Ubuntu desktop with your dev tools (Sublime Text, Visual Studio Code, etc.), that you can remotely connect to and comfortably work on, spanning all your local monitors. Like this:

We'll use TigerVNC. RealVNC 4 that comes with Ubuntu 16.04 can also be used, but it lacks the X extensions that are required for a well behaved multi monitor setup. Also, Visual Studio Code can't run on RealVNC 4 without a special patched version of libxcb.so.1.

Ubuntu 18.04

Desktop edition

sudo apt update
sudo apt install --no-install-recommends openssh-server tigervnc-standalone-server tigervnc-common

sudo su
cat /etc/X11/Xvnc-session
mv /etc/X11/Xvnc-session /etc/X11/Xvnc-session.orig
cat > /etc/X11/Xvnc-session << "EOF"
#!/bin/sh
export GNOME_SHELL_SESSION_MODE=ubuntu
export XDG_CURRENT_DESKTOP=ubuntu:GNOME
vncconfig -nowin &
exec /etc/X11/Xsession
vncserver -kill $DISPLAY
EOF
chmod +x /etc/X11/Xvnc-session
exit

# Start the VNC session (this must be run as your user from an SSH session after each reboot)
vncserver

# To stop the VNC session
vncserver -kill

Server edition

sudo apt-get update
sudo apt install --no-install-recommends tigervnc-standalone-server tigervnc-common ubuntu-desktop

And then followed by the same procedure with /etc/X11/Xvnc-session and vncserver as for desktop.



For additional desktop software, I recommend using the Ubuntu Software Center, which will install Snap packages for popular desktop software.
# Install the Ubuntu Software Center
sudo apt install gnome-software


Ubuntu 16.04

I only tried with server edition on 16.04, so adapt as needed.
sudo apt-get update

sudo apt-get install --no-install-recommends ubuntu-desktop gnome-terminal unity-lens-applications unity-lens-files gnome-settings-daemon
sudo apt-get install --no-install-recommends software-center

wget https://bintray.com/tigervnc/stable/download_file?file_path=ubuntu-16.04LTS%2Famd64%2Ftigervncserver_1.8.0-1ubuntu1_amd64.deb -O tigervncserver_1.8.0-1ubuntu1_amd64.deb
sudo dpkg -i tigervncserver_1.8.0-1ubuntu1_amd64.deb
sudo apt-get install -f

mkdir $HOME/.vnc/
cat > $HOME/.vnc/xstartup <<"EOF"
#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
/etc/X11/xinit/xinitrc &
vncconfig -nowin &
/usr/lib/x86_64-linux-gnu/unity/unity-panel-service &
/usr/lib/x86_64-linux-gnu/indicator-datetime/indicator-datetime-service &
/usr/lib/x86_64-linux-gnu/indicator-keyboard/indicator-keyboard-service &
unity &
EOF
chmod +x $HOME/.vnc/xstartup

# some kde or qt apps seem to look ugly without this package
sudo apt-get install kde-style-breeze-qt4

# Start the VNC session (this must be run as your user from an SSH session after each reboot)
vncserver

# To stop the VNC session
vncserver -kill :1
For Additional desktop software, I recommend using Snap:
sudo apt install snap

# For example install Visual Studio Code, Chrome, and Sublime, like this
sudo snap install vscode --classic
sudo snap install chromium
sudo snap install sublime-text --classic

Connecting

Use the TigerVNC client to take advantage of the dynamic resizing and multi-screen features. Binaries for Win/Mac/Linux can be found on their website.

Open the TigerVNC menu by pressing F8, and note the shortcut keys here for full screen, minimize, etc. Copy the remote .vnc/passwd file locally and pass it to the TigerVNC client with the -PasswordFile= option to avoid having to type your password repeatedly. For example, I connect from my Windows box using a cmd file with this content:
start "" "C:\utils\vnc\vncviewer64-1.8.0.exe" "yourRemoteServer:5901" -PasswordFile=C:\utils\vnc\passwd


Secure connection

If you are connecting over the internet, you'll want to use an SSH tunnel to secure the unencrypted VNC. In that case you can start the VNC server in a mode where it only listens on localhost, and then use SSH port forwarding.
vncserver  -localhost=yes -nolisten tcp
Connect using your preferred SSH client, and set up port forwarding to localhost:5901, for example from your local port 5901.

4 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete

  3. Hi, I'm looking for a solution of multi screen on a monitor-less ubuntu server.
    I have 2 monitors on a thin client and i hope use both monitors as remote screens like what u did.
    Tried with tightvnc, realvnc,turbovnc but doesn't find a way works on me.
    Your work gives me hope for this.
    I have 2 questions.
    1, My ubuntu is 18.04 desktop but XFCE edition. So how to modify the Xvnc-session for xfce.
    2, I can't see any option related to the multi-monitor/screen/display in your post. How does it work? what if i want set geometer for both monitors?
    Thanks.

    ReplyDelete
    Replies
    1. Hey Softparade. If you use TigerVNC for both client and server, it'll probably just work out of the box as you want it. I highly recommend you try TigerVNC before wasting more time trying to hack TightVNC, RealVNC or any other VNC to do multi monitor. I tried, and it's a pain.

      (If you for some reason cannot use tigervnc, then check out these lines I was experimenting with before I discovered TigerVNC: https://gist.github.com/allanrbo/53ea59077fb2aa33d0b74d64e1d96cd3 )

      Delete