Remotely Connecting to Ubuntu via VNC
Overview
A VNC (Virtual Network Computing) is a graphical desktop sharing system that can remotely control another computer.
On your local computer, please install a supported VNC Client:
On macOS, you can use the built-in Screen Sharing program, or can use a cross-platform app like RealVNC.
On Linux, you can choose from many options, including
vinagre
,krdc
, RealVNC, or TightVNC.
Using Windows
If you don’t already have PuTTY installed, please follow the link SSH to Instance using Windows.
Also, download a supported VNC Client, if you haven’t already. In this example, we will use TightVNC.
Connect to your server through PuTTY and open the terminal window.
On your server, update your list of packages.
sudo apt update
Now, install the Xfce desktop environment and TightVNC server
sudo apt install xfce4 xfce4-goodies sudo apt install tightvncserver
To complete the VNC server configuration, create the initial configuration file and set up a secure password.
vncserver
Passwords must be between 6-8 characters. If your password has more than 8 characters, it will be automatically truncated.
After setting your password, the following should appear withyour_hostname
=your_instancename
:Note: if you want to change your password or add a view-only password, you can do so with the following command:
Now we configure the VNC server, by first stopping the default VNC server instance.
Backup and modify the startup file.
This will create a new
xstartup
file and open it in the text editornano
. Add the following lines:To save and exit, press
CTRL+X
,Y
, thenENTER
We make the startup file executable and restart VNC server.
Now we connect to the VNC Desktop.
Right-click on the top bar of the terminal window, then select Change Settings.On the directory on the left-hand side of PuTTY, expand SSH and click on Tunnels.
In Source Port enter:59000
In Destination enter:localhost:5901
Click Add, then Apply.Open your VNC viewer client and connect to
localhost:59000
. You should see something like the following:
The VNC service needs to be manually started after every instance reboot (Steps 5-10) or the service can be automatically started after instance reboot with the following optional setup: Setup VNC as System Service
Also note, the SSH tunnel (Step 9) must be configured after every time the SSH client is started in order to connect to the VNC server. Please visit the following section to save the SSH tunnel information to PuTTY: Setup SSH Tunnel Information in PuTTY
Using Mac or Linux
If you haven’t already, please download a supported VNC Client. In this example, we will use TightVNC.
Connect to your server and open the terminal window.
Instructions on how to connect to your server through SSH can be found here:
SSH to Instance using Mac and LinuxOn your server, update your list of packages.
Now, install the Xfce desktop environment and TightVNC server
To complete the VNC server configuration, create the initial configuration file and set up a secure password.
Passwords must be between 6-8 characters. If your password has more than 8 characters, it will be automatically truncated.
After setting your password, the following should appear withyour_hostname
=your_instancename
:Note: if you want to change your password or add a view-only password, you can do so with the following command:
Now we configure the VNC server, by first stopping the default VNC server instance.
Backup and modify the startup file.
This will create a new
xstartup
file and open it in the text editornano
. Add the following lines:To save and exit, press
CTRL+X
,Y
, thenENTER
We make the startup file executable and restart VNC server.
Now we connect to the VNC Desktop, by creating an SSH connection.
In the terminal, input the following:Replace
ubuntu
andyour_server_ip
with the sudo non-root username and server IP address.
Note: it may be needed to replace127.0.0.1
withlocalhost
, depending on the Ubuntu version.Open your VNC client and connect to
localhost:59000
.
The VNC service needs to be manually started after every instance reboot (Steps 5-9) or the service can be automatically started after instance reboot with the following optional setup: Setup VNC as System Service
Also note, the SSH tunnel (Step 8) must be configured after every time the client is started in order to connect to the VNC server.
Setup VNC as System Service
The following steps will configure the VNC server to start every time the server boots up.
Create new unit file
Add the following lines and replace the
ubuntu
value in User, Group, Working Directory and PIDFILE username as appropriate:Save and close the file.
Enable the new unit file.
Turn off current VNC server instance.
Start systemd service.
You can use the following command to verify that it started.
The output should say
active (running)
To reconnect to the server, start your SSH tunnel (Step 8 in either of instructions above).
With this setup, users only need to create the SSH tunnel after every reboot to connect to the VNC server, starting Steps 8 in Using Windows/ Using Max or Linux instructions, to access the VNC server.
For PuTTY users, this can also be combined with Setup SSH Tunnel Information in PuTTY for even quicker connection.
Setup SSH Tunnel Information in PuTTY
Open a new PuTTY sesssion and enter in the Host Name information, but do not click
Open
yet.Under
Saved Sessions
, label what you want the server and SSH information to be known as. Then clickSave
.On the directory on the left-hand side of PuTTY, expand
SSH
and click onTunnels
.
In Source Port enter:59000
In Destination enter:localhost:5901
Click Add.Return back to the default main page, by clicking on
Session
in the directory.
ClickSave
once again.The next time you reboot the instance and reopen PuTTY, load the saved session. If you click on
SSH
→Tunnels
, you should find the added SSH port forwarding. Then clickOpen
.