How To Connect To VNC Server Ussing SSH Tunnel

LawrenceLawrence Moderator

Introduction

VNC is short for Virtual Network Computing. It’s a simple method for sharing a graphical desktop environment. For example, if you install VNC on your hosted server, you could connect to its graphical desktop environment remotely.

In Time4VPS you are able to install VNC template really easy and fast, only with few mouse clicks:
  1. Login to the Clients Portal;
  2. Select at the top of menu the "My Services > VPS" tab;
  3. Press the "Manage" button at the service table;
  4. Press the "Install OS" button;
  5. Choose operating system, agree with warning and press "Continue";
  6. Wait for 5-10 minutes and refresh VPS management page.

1. VNC server configuration indicating to listen only for connections from localhost


Open vncservers file:

CentoOS: nano /etc/sysconfig/vncservers

Ubuntu:
nano /etc/vncserver/vncservers.conf

Now add "-localhost" on the end of the VNCSERVERARGS line, just like shown below:

VNCSERVERARGS[1]="-geometry 1024x768 -localhost"

Restart VNC service:

service vncserver restart


2. Connecting to server via SSH tunnel [In Linux systems]

Execute this command in the console on you computer running Linux operating system to establish SSH tunnel:

ssh -L 5901:localhost:5901 -N -f -l vncuser IP_of_the_server

In this command:

-L 5901:localhost:5901 : Specifies that the given port on the local (client) host is to be forwarded to the given host and port on the remote side. Here you are using port 5901 on the localhost to be forward to sshserver.mydomain.com on the 5901 port.
-N : Do not execute a remote command i.e. just forward ports.
-f : Requests ssh to go to background just before command execution. Requests ssh to go to background just before command execution. Once password supplied it will go to background and you can use prompt for type commands on local system.
-l vncuser : vncuser is the user to log in as on the remote machine.
IP_of_the_server : IP address or hostname of your server.

Now you are able to connect to the server with VNC clients like TigerVNC, TightVNC and so on. Port for connection to VNC is: localhost:5901


2. Connecting to server via SSH tunnel using PuTTY [In Windows systems]

Under Connection -> SSH -> Tunnels add:

Source port: 5901
Destination: localhost:5901


And connect to your server at its IP address and port 22 via PuTTY.


And then connect to localhost:5901 via a VNC viewer such as TightVNC TigerVNC, TightVNC and so on.
Sign In or Register to comment.