{"id":4361,"date":"2019-10-06T15:27:07","date_gmt":"2019-10-06T12:27:07","guid":{"rendered":"https:\/\/kifarunix.com\/?p=4361"},"modified":"2024-03-12T22:26:39","modified_gmt":"2024-03-12T19:26:39","slug":"connect-to-vnc-server-via-ssh-tunnel","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/connect-to-vnc-server-via-ssh-tunnel\/","title":{"rendered":"Connect to VNC Server via SSH Tunnel"},"content":{"rendered":"\n<p>How do you remotely connect to a VNC server? Well in this guide, we are going to learn how to connect to VNC server via SSH tunnel. VNC connections and unencrypted and thus poses security risks. To secure VNC connection, connections can be made through the use of SSH protocol.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Connecting to VNC Server via SSH Tunnel<\/h2>\n\n\n\n<p>In our previous guide, on how to <a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/install-and-configure-vnc-server-on-centos-8\/\" target=\"_blank\">install and configure VNC server on CentOS 8<\/a>, we saw how to test local VNC server connection using <a rel=\"noreferrer noopener\" aria-label=\"TigerVNC client (opens in a new tab)\" href=\"https:\/\/tigervnc.org\/doc\/vncviewer.html\" target=\"_blank\">TigerVNC client<\/a>, <code>vncviewer<\/code>.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You can connect to a VNC server through the VNC client (<code><strong>vncviewer<\/strong><\/code>) with the <code><strong>-via<\/strong><\/code> command line option which enables it to automatically create an encrypted TCP tunnel to VNC server before connection is established between the client and the server. It then connects to the server through that tunnel. It basically invokes SSH local port forwarding.<\/li>\n\n\n\n<li>You can also connect to VNC server using SSH local port forwarding. Once connection is established, you can locally connect to VNC server via vncviewer.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Connect to VNC Server with vncviewer -via Option<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Install TigerVNC Client on CentOS\/RHEL Derivatives<\/h4>\n\n\n\n<p>TigerVNC client (<strong><code>vncviewer<\/code><\/strong>) is provided by the <strong>tigervnc<\/strong> package on CentOS and similar derivatives. In case you have not already installed it, simply run the command below to install;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>dnf install tigervnc<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Install TigerVNC Client on Ubuntu\/Debian Derivatives<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt install tigervnc-viewer<\/code><\/pre>\n\n\n\n<p>You can even use xvnc4viewer;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt install xvnc4viewer<\/code><\/pre>\n\n\n\n<p>Once the installation is done, you can now connect to a VNC server by executing the command below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vncviewer -via USER@HOST [host:displayNum]<\/code><\/pre>\n\n\n\n<p>Where:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>USER<\/code><\/strong>: is any user that can ssh into the VNC server<\/li>\n\n\n\n<li><strong><code>HOST<\/code><\/strong>: is the VNC server address. It can be IP address or hostname (if you have DNS)<\/li>\n\n\n\n<li><strong><code>[host:displayNum]<\/code><\/strong>: specifies the display number to connect to on the VNC server. If you restricted VNC access to allow only encrypted connections from the loopback interface, you would simply use the <code>localhost:1<\/code> to connect to the display number 1. Otherwise, you can specify the IP address or hostname if VNC allows connection on all interfaces.<\/li>\n<\/ul>\n\n\n\n<p>For example, to login to second display number of the VNC server accepting connections on loopback interface as user amos;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vncviewer -via amos@192.168.56.123 localhost:2<\/code><\/pre>\n\n\n\n<p>When run, the command first prompts you to enter the SSH password. After that, you are prompted to enter the password to access the specified display number.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>VNC Viewer Free Edition 4.1.1 for X - built Feb 25 2015 22:57:51\nCopyright (C) 2002-2005 RealVNC Ltd.\nSee http:\/\/www.realvnc.com for information on VNC.\namos@192.168.56.123's password: <strong>SSH PASSWORD<\/strong>\n\nSun Oct  6 13:52:08 2019\n CConn:       connected to host localhost port 5599\n CConnection: Server supports RFB protocol version 3.8\n CConnection: Using RFB protocol version 3.8\nPassword: <strong>DISPLAY-NUMBER PASSWORD<\/strong>\n...<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Connect to VNC Server via SSH Local Port Forwarding<\/h3>\n\n\n\n<p>With ssh local port forwarding to the VNC server, from your desktop Linux system with SSH client installed, execute the command;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ssh -L 5001:localhost:5901 user@VNC-SERVER-ADDRESS<\/code><\/pre>\n\n\n\n<p>Where<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Option <strong><code>-L<\/code><\/strong> specifies SSH local port forwarding<\/li>\n\n\n\n<li><strong><code>5001<\/code><\/strong> is the local port on the local Linux system from where you will connect to remote VNC server.<\/li>\n\n\n\n<li><strong><code>locahost:5901<\/code><\/strong> is the remote VNC server and the display number to connect to. (In this case, it is the same VNC server as <strong><code>VNC-SERVER-ADDRESS<\/code><\/strong> since we configured it to allow connections on loopback interface only)<\/li>\n\n\n\n<li><strong><code>user@VNC-SERVER-ADDRESS<\/code><\/strong> is the SSH user for login to VNC Server.<\/li>\n<\/ul>\n\n\n\n<p>For example, to connect to display number 1 on the remote VNC server  (192.168.56.123), that allows VNC connections only on loopback interface, from the local system through SSH tunnel, simply run;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ssh -L 5001:localhost:5901 amos@192.168.56.123<\/code><\/pre>\n\n\n\n<p>When prompted, enter the password for logging as the specified user.<\/p>\n\n\n\n<p>Once the tunnel, you can then connect to VNC server on the specified port from another terminal by running;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vncviewer localhost:5001<\/code><\/pre>\n\n\n\n<p>When run, the command prompts for the VNC session password.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>VNC Viewer Free Edition 4.1.1 for X - built Feb 25 2015 22:57:51\nCopyright (C) 2002-2005 RealVNC Ltd.\nSee http:\/\/www.realvnc.com for information on VNC.\n\nSun Oct  6 15:10:15 2019\n CConn:       connected to host localhost port 5001\n CConnection: Server supports RFB protocol version 3.8\n CConnection: Using RFB protocol version 3.8\nPassword: <strong>ENTER VNC SESSION PASSWORD<\/strong>\n...<\/code><\/pre>\n\n\n\n<p>You should now be able to securely connect to your remote VNC server.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/10\/vnc-ssh-connection.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1361\" height=\"692\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/10\/vnc-ssh-connection.png\" alt=\"Connect to VNC Server via SSH Tunnel\" class=\"wp-image-4370\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/10\/vnc-ssh-connection.png?v=1570364417 1361w, https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/10\/vnc-ssh-connection-768x390.png?v=1570364417 768w\" sizes=\"(max-width: 1361px) 100vw, 1361px\" \/><\/a><\/figure>\n\n\n\n<p>If you encounter authentication errors, be sure to disable screen lock for the user.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Related Tutorials<\/h3>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/install-and-configure-vnc-server-on-centos-8\/\" target=\"_blank\">Install and Configure VNC Server on CentOS 8<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/how-to-setup-guacamole-web-based-remote-desktop-access-tool-on-ubuntu-18-04\/\">How to Setup Guacamole Web-based Remote Desktop Access Tool on Ubuntu 18.04<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/how-to-install-and-use-nomachine-remote-desktop-tool-on-ubuntu-18-04\/\" target=\"_blank\">How to Install and Use NoMachine Remote Desktop Tool on Ubuntu 18.04<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-webmin-on-centos-8\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">Install Webmin on CentOS 8<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-and-setup-chrome-remote-desktop-on-ubuntu-18-04\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">Install and Setup Chrome Remote Desktop on Ubuntu 18.04<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How do you remotely connect to a VNC server? Well in this guide, we are going to learn how to connect to VNC server via<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121,993,214,1147],"tags":[1142,1150,1149,335,1148],"class_list":["post-4361","post","type-post","status-publish","format-standard","hentry","category-howtos","category-desktop-environment","category-remote-desktop","category-vnc","tag-centos-8","tag-ssh-port-forwarding","tag-ssh-tunnel","tag-vnc","tag-vncviewer","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/4361"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=4361"}],"version-history":[{"count":6,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/4361\/revisions"}],"predecessor-version":[{"id":21234,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/4361\/revisions\/21234"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=4361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=4361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=4361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}