Setting up VNC Server
To set up VNC server on Ubuntu, follow these steps:
1. Install a VNC server software. A popular option is TightVNC:
sudo apt-get update
sudo apt-get install tightvncserver
sudo apt-get install tightvncserver
2. Start the VNC server and set a password:
vncserver
3. Stop the VNC server:
vncserver -kill :1
4. Use your favourite editor to edit the configuration file ~/.vnc/xstartup:
If you're a fan of vim:
vim ~/.vnc/xstartup
If you're a fan of nano:
nano ~/.vnc/xstartup
5. Add the following lines to the file:
#!/bin/sh
xrdb $HOME/.Xresources
startxfce4 &
6. Start the VNC server with the following command:
vncserver
7. Connect to the VNC server using a VNC client from your local location.
The connection address will be in the format of: <host>:<display_number>
As an example, if your IP address is 123.123.123.111 then your connection will be: 127.0.0.1:5901 if your <display number> is 1
Note: You may need to open the firewall for the VNC port, which is 5901 by default, though from a security perspective, it is better to tunnel your VNC server through SSH rather than opening port 5901 to the world.
Securing VNC so it runs through SSH
On the client machine, use the following command to create the SSH tunnel:
ssh -L 5901:localhost:5901 <user>@<server_IP>
Connect to the VNC server using a VNC client. The connection address will be localhost:1.
Note: The SSH connection must be kept open while using the VNC server. The VNC server will automatically shut down if the SSH connection is closed.
Discussion