<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
>

<channel>
	<title>G-Loaded Journal &#187; VNC</title>
	<atom:link href="http://www.g-loaded.eu/tag/vnc/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.g-loaded.eu</link>
	<description>An open-source software and technology related journal</description>
	<lastBuildDate>Thu, 02 Sep 2010 17:01:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
		<item>
		<title>Set up the VNC Server in Fedora</title>
		<link>http://www.g-loaded.eu/2005/11/10/configure-vnc-server-in-fedora/</link>
		<comments>http://www.g-loaded.eu/2005/11/10/configure-vnc-server-in-fedora/#comments</comments>
		<pubDate>Thu, 10 Nov 2005 13:28:16 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Administration]]></category>
		<category><![CDATA[Encryption]]></category>
		<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[Remote]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[VNC]]></category>

		<guid isPermaLink="false">http://www.g-loaded.eu/2005/11/10/configure-vnc-server-in-fedora/</guid>
		<description><![CDATA[This article describes in brief how to configure VNC server instances for one or multiple users on a remote machine, how to use VNC to start graphical applications on boot and finally how to enhance security by connecting to the server through encrypted SSH tunnels.]]></description>
			<content:encoded><![CDATA[<p>&quot;<em><strong>Virtual Network Computing (VNC)</strong> is a desktop protocol to remotely control another computer. It transmits the keyboard presses and mouse clicks from one computer to another relaying the screen updates back in the other direction, over a network.</em>&quot; -WikiPedia-</p>
<p>This article describes in brief how to configure <strong>VNC server</strong> instances for one or multiple users on a remote machine, how to use <strong>VNC</strong> to start graphical applications on boot and finally how to enhance <strong>security</strong> by connecting to the server through encrypted <strong>SSH</strong> tunnels.<br />
<span id="more-93"></span></p>
<h4>Prerequisites</h4>
<p>A <strong>user account</strong> should exist on the remote machine.<br />
The RPM packages <strong>vnc-server</strong> and <strong>vnc</strong> should be installed on the remote machine and your workstation respectively.</p>
<h4>Setting up the server</h4>
<p>I assume that we have setup a remote user account, named &quot;<strong>leopard</strong>&quot; and we want to start an X session through VNC for this user.</p>
<p>In Fedora Core or Red Hat based distros in general, all we have to do is define the VNC server instances in <strong>/etc/sysconfig/vncservers</strong>. These will be started by the vncserver initscript. This has to be done <strong>as root</strong>. Edit this file so that it contains the following:</p>
<pre class="codesnp">VNCSERVERS=&quot;3:leopard&quot;
VNCSERVERARGS[3]=&quot;-geometry 1024x768 -depth 16&quot;</pre>
<p>With these we define that a vnc server instance should be started as user leopard on <strong>display 3</strong> and we also set some options for this server such as <strong>resolution</strong> and <strong>color depth</strong>. Each VNC server instance <em>listens on port 5900 plus the display number</em> on which the server runs. In our case, leopard&#8217;s vnc server would listen on <strong>port 5903</strong>.</p>
<p>For multiple vnc instances <strong>/etc/sysconfig/vncservers</strong> would look like this:</p>
<pre class="codesnp">VNCSERVERS=&quot;1:tiger 2:albatros 3:leopard&quot;
VNCSERVERARGS[1]=&quot;-geometry 1024x768 -depth 16&quot;
VNCSERVERARGS[2]=&quot;-geometry 800x600 -depth 8&quot;
VNCSERVERARGS[3]=&quot;-geometry 1024x768 -depth 16&quot;</pre>
<p>These would listen on ports <strong>5901</strong>, <strong>5902</strong>, <strong>5903</strong> respectively.</p>
<h4>User Configuration</h4>
<p>There is one more thing that needs to be done on the remote machine. User leopard&#8217;s vnc password needs to be set. So, as user leopard give the command:</p>
<pre class="console"># vncpasswd</pre>
<p>We are prompted for a password. This is the password that we will use when we connect to leopard&#8217;s vnc server instance. This password is saved in <strong>/home/leopard/.vnc/passwd</strong>.</p>
<h4>Start the VNC server</h4>
<p>After the initial configuration is done we restart the vnc service. As root:</p>
<pre class="console"># service vncserver restart</pre>
<p>To make VNC server to start on boot:</p>
<pre class="console"># chkconfig vncserver on</pre>
<h4>More User Configuration</h4>
<p>After the VNC service is started, some new files are created in <strong>/home/leopard/.vnc/</strong> directory. These include leopard&#8217;s vnc server log file, pid file and an X startup script. As user leopard we edit the script in order to customize some settings. The default <strong>/home/leopard/.vnc/xstartup</strong> script contains some commands that are executed when the VNC server is started. These include:</p>
<pre class="codesnp">xsetroot -solid grey
vncconfig -iconic &#38;
xterm -geometry 80x24+10+10 -ls -title &quot;$VNCDESKTOP Desktop&quot; &#38;
twm &#38;</pre>
<p><strong>xsetroot</strong> in this case sets the background color.<br />
<strong>vncconfig</strong> is a supplementary program that can be used to control the vnc server. Apart from this, when run without arguments it acts as a helper application and its main purpose is to provide support for clipboard transfers between the client (vncviewer) and the vnc server.<br />
<strong>xterm</strong> starts an xterm terminal.<br />
<strong>twm</strong> starts the X server&#8217;s default window manager. We probably want to change that to a more user friendly window manager, eg fluxbox.</p>
<p>The VNC server, apart from letting us control a remote machine using a graphical interface, it <strong>serves as a way to start graphical applications on boot</strong>. For example, I want my favourite p2p program, amule, to start on boot. So, I add this to the <strong>/home/leopard/.vnc/xstartup</strong> script. This is how my xstartup file looks like:</p>
<pre class="codesnp">xsetroot -solid grey
vncconfig -iconic &#38;
xterm -geometry 80x24+10+10 -ls -title &quot;$VNCDESKTOP Desktop&quot; -e ./menu &#38;
amule &#38;
fluxbox &#38; </pre>
<p><strong>menu</strong> is a script of mine that is executed when xterm is started.<br />
Remember to put the &quot;<strong>&#38;</strong>&quot; symbol after each command, so that it goes to the background and the xstartup script continues on.</p>
<p>Restart the VNC service for the changes to take effect. As root:</p>
<pre class="console"># service vncserver restart</pre>
<h4>Connect to the VNC server</h4>
<p>In our example, leopard&#8217;s vnc server listens for connections on port <strong>5903</strong>. So, <span style="text-decoration:underline;">open this port</span> in the remote machine&#8217;s firewall.</p>
<p>We connect to the remote machine using a vnc viewer. Having installed the <strong>vnc</strong> package, connect to to the server with the following command:</p>
<pre class="console"># vncviewer 192.168.0.1:5903:3</pre>
<p>The general usage is :</p>
<pre class="codesnp">vncviewer [Server's IP]:[Port]:[Display]</pre>
<p>We are prompted for the password and eventually connect to the server. Closing the vncviewer&#8217;s window, does not affect the server or the programs we run on it. If we reconnect everything will be there.</p>
<p><em><span style="text-decoration:underline;">Special Note:</span></em> There is no need, actually it&#8217;s pointless and could give you some trouble, to logoff from your remote X session. If this happens, generally you need to restart the VNC service on the remote machine to get your remote desktop back. If you want to stop working on your remote desktop, just close the vncviewer&#8217;s window and you are done.</p>
<h4>Security</h4>
<p>The VNC protocol is not a secure communication protocol. The use of a vnc password provides security at the level of server access (it&#8217;s vulnerable to brute-force attacks though), but the whole VNC session is transmitted in the clear, without encryption. The easiest, but most effective, way to secure our connection to the VNC server is to connect through an encrypted <strong>SSH tunnel</strong>. This way the whole session will be encrypted.</p>
<p>The rest assume that you have the SSH server up and running on your remote machine (server.example.com) and you know what SSH tunnels are.</p>
<p>So, what we are going to do is to create an encrypted tunnel, and connect to our VNC server through it. We also want this tunnel to be <strong>automatically closed</strong> as soon as we shut down vncviewer. All this is done with the following command:</p>
<pre class="console"># ssh -f -L 25903:127.0.0.1:5903 leopard@server.example.com sleep 10; vncviewer 127.0.0.1:25903:3</pre>
<p>This is what it does:</p>
<ul>
<li><strong>-L 25903:127.0.0.1:5903</strong> forwards our local port 25903 to port 5903 on the remote machine. In other words, it creates the tunnel.</li>
<li><strong>-f</strong> forks the SSH session to the background, while <strong>sleep</strong> is being executed on the remote machine. This ssh option is needed because we want to execute the following command (vncviewer) in the same <em>local</em> machine&#8217;s terminal.</li>
<li><strong>vncviewer</strong> connects to the forwarded local port 25903 in order to connect to the VNC server through the encrypted tunnel.</li>
</ul>
<p>The <strong>sleep</strong> command is of major importance in the above line as it keeps the encrypted tunnel open for 10 seconds. If no application uses it during this period of time, then it&#8217;s closed. Contrariwise, if an application uses it during the 10 sec period, then the tunnel remains open until this application is shut down. This way the tunnel is <strong>automatically closed</strong> at the time we close vncviewer&#8217;s window, without leaving any SSH processes running on our workstation. This is pure convenience! More information can be found at the <a href="http://www.g-loaded.eu/2006/11/24/auto-closing-ssh-tunnels/">Auto-closing SSH Tunnels</a> article.</p>
<p>Using SSH tunnels to conect to your VNC server has two advantages:</p>
<ol>
<li>The whole session is encrypted.</li>
<li>Keeping port 5903 open on your remote machine <em>is no longer needed</em>, since all take place through the SSH tunnel. So, noone will know that you run a VNC server on the remote machine.</li>
</ol>
<h4>Further Reading</h4>
<p>I recommend that you read the man pages. Everything is in there:</p>
<pre>
# man vncserver
# man Xvnc
# man vncconfig
# man vncviewer
# man ssh
</pre>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2005/11/10/configure-vnc-server-in-fedora/">Set up the VNC Server in Fedora</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>


<h4>Related Articles</h4>

<ul><li><a href="http://www.g-loaded.eu/2005/10/20/ssh-tunnels-headaches/" rel="bookmark">SSH Tunnels Headaches</a></li>
<li><a href="http://www.g-loaded.eu/2006/11/24/auto-closing-ssh-tunnels/" rel="bookmark">Auto-closing SSH tunnels</a></li>
<li><a href="http://www.g-loaded.eu/2005/11/10/ssh-with-keys/" rel="bookmark">Setup the SSH server to use keys for authentication</a></li>
<li><a href="http://www.g-loaded.eu/2006/11/06/netcat-a-couple-of-useful-examples/" rel="bookmark">Netcat &#8211; a couple of useful examples</a></li>
<li><a href="http://www.g-loaded.eu/2010/03/26/python-ssh-server-unix-twisted-conch/" rel="bookmark">Python SSH Server for UNIX Systems using Twisted.conch</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2005/11/10/configure-vnc-server-in-fedora/feed/</wfw:commentRss>
		<slash:comments>39</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
	</channel>
</rss>
