How to install VNC server on a Cloud VM running on linux via ssh and start a remote GUI session from desktop

Here’s a step-by-step guide on how to install a VNC server on a Linux VM and start a remote GUI session from a Windows desktop:

  1. SSH into your Linux VM

    Open your terminal and SSH into your VM using the following command:

    ssh username@your_server_ip
    

    Replace username with your actual username and your_server_ip with the IP address of your server.

  2. Update Your Server

    Before you install anything, it’s a good idea to update your server’s package lists:

    sudo apt-get update
    
  3. Install the VNC Server

    Install the VNC server using the following command:

    sudo apt-get install tightvncserver
    

    This will install TightVNC, a free remote control software package.

  4. Start the VNC Server

    Start the VNC server using the following command:

    vncserver :1 -geometry 1920x1080 -depth 24
    

    This will start a VNC server session with a display number of 1 and a resolution of 1920×1080 pixels.

  5. Set a VNC Password

    The first time you start the VNC server, you will be prompted to set a password. This password will be used to connect to the VNC server from your VNC client.

  6. Install a Desktop Environment

    If your server doesn’t already have a desktop environment installed, you will need to install one. For example, to install the XFCE desktop environment, you can use the following command:

    sudo apt-get install xfce4 xfce4-goodies
    

    Once the desktop environment is installed, you will need to configure your VNC server to use it. Open the ~/.vnc/xstartup file in a text editor:

    nano ~/.vnc/xstartup
    

    And add the following lines to the file:

    #!/bin/bash
    xrdb $HOME/.Xresources
    startxfce4 &
    

    Save and close the file. Then make it executable with the following command:

    sudo chmod +x ~/.vnc/xstartup
    
  7. Restart the VNC Server

    Finally, restart your VNC server with the following command:

    vncserver :1 -geometry 1920x1080 -depth 24
    

Now, on your Windows machine:

  1. Install a VNC Client

    There are many VNC clients available for Windows, but one of the most popular is RealVNC’s VNC Viewer, which is free for personal use. You can download it from the RealVNC website.

  2. Connect to the VNC Server

    Open VNC Viewer and enter the following in the “VNC Server” field:

    your_server_ip:1
    

    Replace your_server_ip with the IP address of your server. The :1 corresponds to the display number of the VNC server session you started earlier.

    Click “Connect”. You will be prompted to enter the password you set when you started the VNC server. After entering the password, you should be connected to your Linux VM and see the desktop environment you installed.

Remember, when you’re done with your VNC session, you should stop the VNC server on your Linux VM with the following command:

vncserver -kill :1

This will stop the VNC server session with a display number of 1.


Posted

in

,

by

Comments

Leave a Reply