How to Install Vnc Viewer on Ubuntu 16.04

In this guide we will install the xfce4 desktop environment and VNC server to allow us to control Ubuntu 20.04, 18.04 & 16.04 remotely from Linux, Mac or Windows.

Prerequisites

You should use a non-root user account with sudo privileges.

Please see

  • Initial Server Setup for Ubuntu 20.04
  • Initial Server Setup for Ubuntu 18.04 / 19.10
  • Initial Server Setup for Ubuntu 16.04 / 17.10 for more details.

You will also need to download and install a VNC client for your OS. We recommend the following:

Windows VNC Clients

  • VNC Viewer (RealVNC), TightVNC or UltraVNC
  • For Windows users, you will also need the PuTTY client in order to create an SSH tunnel

MacOS VNC Clients

  • VNC Viewer (RealVNC) or you can use the inbuilt screen sharing utility for Mac.

Linux VNC Clients

  • Ubuntu Desktop comes preloaded with a VNC-capable client called Remmina
  • VNC Viewer (RealVNC), TightVNC, vinagre, krdc

1. Install Xfce and VNC

Begin by updating the package lists.

          sudo apt update        

Now install Xfce4 and VNC server. Press y and ENTER if prompted to install.

          sudo apt install xfce4 xfce4-goodies tightvncserver        

2. Configure VNC Server

Run vncserver.

          vncserver        

You will be asked to enter a password. Generate a password 8 chars long, any longer and it will be truncated.

You will also be asked if you want a view-only password where the user can only view and not control the remote server. You can skip this if you don't require it.

VNC Server should now be running.

xauth: file /home/john/.Xauthority does not exist  New 'X' desktop is ubuntu_server:1  Creating default startup script /home/john/.vnc/xstartup Starting applications specified in /home/john/.vnc/xstartup Log file is /home/john/.vnc/ubuntu_server:1.log

We now need to edit thexstartup file. Before doing so, kill VNC service.

          vncserver -kill :1        

Back up xstartup file.

          cp ~/.vnc/xstartup ~/.vnc/xstartup.bak        

Editxstartup file.

          nano ~/.vnc/xstartup        

Add the following to the bottom of the file.

~/.vnc/xstartup

          startxfce4 &        

This will tell VNC to start the Xfce desktop environment when VNC starts.

Save and close. (pressCTRL +X, pressY and then pressENTER)

Make the xstartup file executable.

          sudo chmod +x ~/.vnc/xstartup        

Now startvncserver again.

          vncserver        
New 'X' desktop is ubuntu_server:1  Starting applications specified in /home/john/.vnc/xstartup Log file is /home/john/.vnc/ubuntu_server:1.log

3. Create SSH Tunnel

VNC server is now running, but in order to encrypt communications between the VNC client and server, we must create an SSH tunnel and connect through it. We can do this by binding port 5901 of the remote connection to port 5901 on your local machine.

Linux and Mac

You can create an SSH tunnel easily using terminal. Replace john with your non-root username andyour_server_ip with your server IP.

          ssh -L 5901:127.0.0.1:5901 -C -N -l john your_server_ip        

Enter your Linux password (not your VNC password) and skip to Step 4 below.

Windows

You will need the PuTTY client to create an SSH Tunnel.

In PuTTY, select Connection > SSH > Tunnels.

In Source Port, enter 5901

In Destination, add your_ip:5901

Click Add.

In the left-hand category menu, go to Session.

In Host Name, enter your non-root Linux username and IP (e.g, john@192.168.1.10).

In Saved Sessions, enter "SSH Tunnel" (you can call this whatever you like).

Click Save and then click Open to start the connection.

PuTTY SSH tunnel and 5901 port forward

When prompted, enter your Linux password to log in (not your VNC password).

Once logged in, to check if the SSH tunnel is up,right-click the PuTTY title bar to invoke the context menu, then click Event Log.

If the tunnel is up, at the bottom of the log, you should see Local port 5901 forwarding to ip_address:5901

PuTTY SSH tunnel and 5901 port forward

You can now continue to the next step to connect to the VNC server using your VNC client.

4. Connect to VNC

Port 5901 of the remote connection should now be bound to port 5901 on your local machine, creating a secure SSH tunnel. You should now be able to connect to the VNC server using locahost:5509 with your VNC client of choice.

VNC Viewer on Windows and MacOS

There are many different VNC viewers for Windows and MacOS, but in this guide we are using VNC Viewer (RealVNC).

Run VNC Viewer, click File and click New Connection.

In the VNC Server field, enter localhost:5901 and click OK.

RealVNC connection window

Double-click localhost:5901.

VNC Viewer Connections screen

When prompted for a password, enter the VNC password you created earlier, checkRemember Password, and click OK.

If you see a warning about Unencrypted connection, ignore it and click Continue. (VNC Viewer is not aware that we are using an encrypted SSH tunnel)

If VNC connects successfully, you should see the default Xfce desktop.

Click Use default config if prompted.

Xfce default Desktop via VNC

Linux

If you are using Ubuntu Desktop, it comes preloaded with a VNC-capable client called Remmina. Just type "VNC" or "remmina" in the dash to start it.

In the Name field, Enter a profile name of your choice.

In the Server field, enterlocalhost::5901.

In the Password, field, enter your VNC password your created earlier.

Click Connect.

Remmina Ubuntu VNC connection window

If VNC connects successfully, you should see the default Xfce desktop.

ClickUse default config if prompted.

Xfce default Desktop via VNC

5. Run VNC as a Service

You should now make VNC a service so that it starts automatically should you ever reboot your server.

Create a new unit file for VNC. A unit file encodes information about a service

          sudo nano /etc/systemd/system/vncserver@.service        

Paste in the following, replacing john with your own user name. You can also change1280x800 to your desired resolution.

/etc/systemd/system/vncserver@.service

          [Unit] Description=Start TightVNC server at startup After=syslog.target network.target  [Service] Type=forking User=john            Group=john            WorkingDirectory=/home/john            PIDFile=/home/john/.vnc/%H:%i.pid ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1 ExecStart=/usr/bin/vncserver -depth 24 -geometry            1280x800            :%i ExecStop=/usr/bin/vncserver -kill :%i  [Install] WantedBy=multi-user.target        

Save and close. (pressCTRL +X, pressY and then pressENTER)

Reload systemd manager configuration.

          sudo systemctl daemon-reload        

Enable the unit file you just created.

          sudo systemctl enable vncserver@1.service        

Kill vncserver.

          vncserver -kill :1        

Start vncserver again.

          sudo systemctl start vncserver@1        

Ensure service is running.

          sudo systemctl status vncserver@1        

If the vncserver is running, you should see:

                                  vncserver@1.service - Start TightVNC server at startup Loaded: loaded (/etc/systemd/system/vncserver@.service; indirect; vendor preset: enabled) Active:                          active (running)                        since Sat 2019-02-16 18:14:22 CET; 6s ago Process: 31449 ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :1 (code=exited, status=0/SUCCESS) Process: 31436 ExecStartPre=/usr/bin/vncserver -kill :1 > /dev/null 2>&1 (code=exited, status=2) Main PID: 31461 (Xtightvnc) Tasks: 57 (limit: 1152) CGroup: /system.slice/system-vncserver.slice/vncserver@1.service        

Now if you ever reboot your server, the VNC Server service should start automatically.

To connect to VNC again, don't forget to start your SSH tunnel in Step 3.

Let me know if this helped. Follow me on Twitter, Facebook and YouTube, or 🍊 buy me a smoothie.

p.s. I increased my AdSense revenue by 200% using AI 🤖. Read my Ezoic review to find out how.

How to Install Vnc Viewer on Ubuntu 16.04

Source: https://devanswers.co/install-vnc-ubuntu-18-04-windows-mac-linux/

0 Response to "How to Install Vnc Viewer on Ubuntu 16.04"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel