Remotely Connecting to CentOS 7 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 SSH to Instance using Windows.
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. First, create user accounts. These accounts will remotely connect to our CentOS 7 server.
    Use the following command to add user accounts and set their passwords. Repeat to add as many users as needed.

    sudo useradd -c "User newuser Configured for VNC Access" newuser1 sudo passwd newuser1
  3. Install GNOME Desktop.

    sudo yum groupinstall "GNOME Desktop" sudo reboot

    Following the reboot, reconnect to your server.

  4. Install TigerVNC for a VNC server.

    sudo yum install tigervnc-server
  5. Configure VNC Service for your clients/accounts.

  6. Open the service unit file for each client.

  7. Press Insert on your keyboard. Then replace and input the following commands under [Service]:

    To save and exit, press the ESC key then type :wq.
    Note: Remember to change the username in the commands from newuser1.
    Additionally, if you have more than one user, you would need to replicate steps 5-7 for each user.
    For example, if I have a second user (newuser2), I would do the following:

  8. Reload and boot all VNC servers. The enable function will start the VNC server at boot time.

    Repeat line 2 for all clients, remembering the replace the port number.

  9. Configure the firewall

    Note: If you have more than one user, also include their port in the firewall rules, like in the following:

  10. Now, we will open a new PuTTY session and change a few of the settings.
    First, ensure the checkbox for Enable X11 forwarding in the left menu under SSH - X11 is checked.

  11. On the directory on the left-hand side of PuTTY, expand SSH and click on Tunnels.
    In Source Port, enter: 5900
    In Destination, enter: your_serverip:5901 or your_serverip:<5900+port_number>
    - Where the port number corresponds to the user you desire. The port number should match the one used in Steps 5-7.
    - Where your_serverip, in this case, should be the IP address and not the Floating IP.
    Click Add, then Open.

  12. In the terminal, switch to your desired user and set VNC server password.

    Note, the display port listed in the outcome of line 2 may differ than the port number itself.

  13. Open your VNC viewer client and connect to localhost:5900
    You should see something like the following:

After the initial setup, every reboot will require users to start at Step 10 to reconnect to the VNC server. This includes creating the SSH tunnel to the desired port. 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:
    SSH to Instance using Mac and Linux

  2. First, create user accounts. These accounts will remotely connect to our CentOS 7 server.
    Use the following command to add user accounts and set their passwords. Repeat to add as many users as needed.

  3. Install GNOME Desktop.

    Following the reboot, reconnect to your server.

  4. Install TigerVNC

  5. Configure VNC Service for your clients/accounts.

  6. Open the service unit file for each client.

  7. Press Insert on your keyboard. Then replace and input the following commands under [Service]:

    To save and exit, press the ESC key then type :wq.
    Note: Remember to change the username in the commands from newuser1.
    Additionally, if you have more than one user, you would need to replicate steps 5-7 for each user.
    For example, if I have a second user (newuser2), I would do the following:

  8. Reload and boot all VNC servers. The enable function will start the VNC server at boot time.

    Repeat line 2 for all clients, remembering the replace the port number.

  9. Configure the firewall

    Note: If you have more than one user, also include their port in the firewall rules, like in the following:

  10. Switch to your desired user and set VNC server password.

    Note, the display port listed in the outcome of line 2 may differ than the port number itself.

  11. Enter the following connection information to use SSH tunneling

    Replace newuser1 and your_server_ip with the appropriate username and server IP address, not Floating IP address.

  12. Open your VNC client and connect to localhost:5900. Once connected, you should see something like the following:

After the initial setup, every reboot will require users to start at Step 10 to reconnect to the VNC server. This includes creating the SSH tunnel to the desired port.

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.

  3. On the directory on the left-hand side of PuTTY, expand SSH and click on X11. Check the box to Enable X11 forwarding.

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

  5. On the directory on the left-hand side of PuTTY, expand SSH and click on Tunnels.
    In Source Port, enter: 5900
    In Destination, enter: your_serverip:5901 or your_serverip:<5900+port_number>
    - Where the port number corresponds to the user you desire. The port number should match the one used in Steps 5-7.
    - Where your_serverip, in this case, should be the IP address and not the Floating IP.
    Click Add.

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

  7. 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. You should also find that the X11 forwarding was also saved. Then click Open.

 

 



Â