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:

Using Windows

If you don’t already have PuTTY installed, please follow the link https://sdsc-ucsd.atlassian.net/wiki/spaces/SC/pages/110034995.
Also, download a supported VNC Client, if you haven’t already. In this example, we will use TightVNC.

  1. Connect to your server through PuTTY and open the terminal window.

  2. On your server, update your list of packages.

    sudo apt update
  3. Now, install the Xfce desktop environment and TightVNC server

    sudo apt install xfce4 xfce4-goodies sudo apt install tightvncserver
  4. 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 with your_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:

  5. Now we configure the VNC server, by first stopping the default VNC server instance.

  6. Backup and modify the startup file.

    This will create a new xstartup file and open it in the text editor nano. Add the following lines:

    To save and exit, press CTRL+X, Y, then ENTER

  7. We make the startup file executable and restart VNC server.

  8. Now we connect to the VNC Desktop.
    Right-click on the top bar of the terminal window, then select Change Settings.

  9. 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.

  10. 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.

  1. Connect to your server and open the terminal window.
    Instructions on how to connect to your server through SSH can be found here:
    https://sdsc-ucsd.atlassian.net/wiki/spaces/SC/pages/110034993

  2. On your server, update your list of packages.

  3. Now, install the Xfce desktop environment and TightVNC server

  4. 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 with your_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:

  5. Now we configure the VNC server, by first stopping the default VNC server instance.

  6. Backup and modify the startup file.

    This will create a new xstartup file and open it in the text editor nano. Add the following lines:

    To save and exit, press CTRL+X, Y, then ENTER

  7. We make the startup file executable and restart VNC server.

  8. Now we connect to the VNC Desktop, by creating an SSH connection.
    In the terminal, input the following:

    Replace ubuntu and your_server_ip with the sudo non-root username and server IP address.
    Note: it may be needed to replace 127.0.0.1 with localhost, depending on the Ubuntu version.

  9. 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.

  1. 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.

  2. Enable the new unit file.

  3. Turn off current VNC server instance.

  4. Start systemd service.

    You can use the following command to verify that it started.

    The output should say active (running)

  5. 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

  1. Open a new PuTTY sesssion and enter in the Host Name information, but do not click Open yet.

  2. Under Saved Sessions, label what you want the server and SSH information to be known as. Then click Save.

  3. 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.

  4. Return back to the default main page, by clicking on Session in the directory.
    Click Save once again.

  5. The next time you reboot the instance and reopen PuTTY, load the saved session. If you click on SSHTunnels, you should find the added SSH port forwarding. Then click Open.