Currently I’ve setup the Ubuntu Server 18.04 LTS from the Azure marketplace and I’m trying to access it via VNC Server setup on the Linux machine. Also, you’ll need a vnc client like RealVNC or you can also use the screen-sharing client available on your Mac.
Login via SSH:
First you need to login to your Linux VM as a non-root user which you’ve created while setting up the VM. To spin up a new Linux VM, you can check out this post. You can use the Cloud shell to connect to your VM using the non-root username and password to your machine via SSH. Use the Connect menu of your VM and copy the SSH command to run in the Cloud shell.
You just need to replace the your_user_name and IP_Address parts in the above command. Enter the password you’re prompted for to complete the Login as SSH.
Install the required packages:
We now need to install the required packages like Xfce desktop environment and VNC Server which are not bundled in the Ubuntu OS by default. Xfce is a free and open-source desktop environment for Unix and Unix like Operating Systems.
Update list of packages:
$ sudo apt update
Install Xfce Desktop environment and wait for the installation to complete:
$ sudo apt install xfce4 xfce4-goodies
Install the VNC Server:
$ sudo apt install tightvncserver
Complete the initial configuration and provide the setup password:
Providing a view-only password is optional. You’ll get the below Output as the initial configuration completes:
Creating default startup script /home/your_user_name/.vnc/xstartup Starting applications specified in /home/your_user_name/.vnc/xstartup Log file is /home/your_user_name/.vnc/your_hostname:1.log
Configure VNC Server:
The VNC Server is by default configured on the port 5901 and display port :1. VNC can launch multiple instances on other ports like :2, :3 and so on.
Let’s first kill the current instance for further configuration that we require:
$ vncserver -kill :1
Killing Xtightvnc process ID <ID>
Backup the xstartup file before modifying:
$ mv ~/.vnc/xstartup ~/.vnc/xstartup.bak
Create a new xstartup file and open in editor:
$ nano ~/.vnc/xstartup
Add the following lines to your file in the nano editor and save it:
~/.vnc/xstartup #!/bin/bash xrdb $HOME/.Xresources startxfce4 &
This is making certain settings to the graphical desktop like colours, themes and fonts. The last line is starting the Xfce desktop. Now, let’s convert the file to an executable and restart:
$ sudo chmod +x ~/.vnc/xstartup $ vncserver
Now, let’s connect to the VNC Server from your Mac by creating a SSH tunnel and use Screen-sharing client to connect.
Run this command on your Mac terminal:
$ ssh -L 5901:127.0.0.1:5901 -C -N -l your_user_name your_server_ip
Do replace the your_user_name with your sudo non-root username and your_server_ip with the IP Address of your Linux VM. Provide the password when prompted for your username.
Now, open your screen sharing App available in the Finder Go Menu on your Mac that says “Connect to Server…”.
Click on Connect and provide your password when prompted again and you’ll see the Xfce Desktop running via Screen-sharing.