<?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/"
	>

<channel>
	<title>Smörgåsbord &#187; xhost</title>
	<atom:link href="http://smorgasbord.gavagai.nl/tags/xhost/feed/" rel="self" type="application/rss+xml" />
	<link>http://smorgasbord.gavagai.nl</link>
	<description>Ambachtelijk bereide beschouwingen.</description>
	<lastBuildDate>Fri, 06 Jan 2012 21:30:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>SOCAT: access your X server&#8217;s domain socket over TCP</title>
		<link>http://smorgasbord.gavagai.nl/2010/01/socat-access-your-x-servers-domain-socket-over-tcp/</link>
		<comments>http://smorgasbord.gavagai.nl/2010/01/socat-access-your-x-servers-domain-socket-over-tcp/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 18:09:11 +0000</pubDate>
		<dc:creator>Wicher</dc:creator>
				<category><![CDATA[Howto]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[socat]]></category>
		<category><![CDATA[X11]]></category>
		<category><![CDATA[xauth]]></category>
		<category><![CDATA[xhost]]></category>

		<guid isPermaLink="false">http://smorgasbord.gavagai.nl/?p=761</guid>
		<description><![CDATA[Access remote X11 servers that have their TCP socket disabled
This happens to me regularly. Someone brings a machine along and I want to display some app, running on my machine, on their display. Networked X11 to the rescue, you say? No, their X11 server is started with &#8216;-nolisten TCP&#8217; wich is the default on most [...]]]></description>
			<content:encoded><![CDATA[<h3>Access remote X11 servers that have their TCP socket disabled</h3>
<p>This happens to me regularly. Someone brings a machine along and I want to display some app, running on my machine, on their display. Networked X11 to the rescue, you say? No, their X11 server is started with &#8216;-nolisten TCP&#8217; wich is the default on most modern Linux distros. Sadly, the TCP socket can&#8217;t be enabled &#8216;in-flight&#8217; — if you decide you <strong>do</strong> fancy a TCP socket after all, you&#8217;ll have to restart your X server which may be a pain if you&#8217;re in the middle of something (besides, restarting is just plain uncool).<br />
But there is a way to expose the Unix domain socket as a TCP socket, with the help of <a href="http://www.dest-unreach.org/socat/">socat</a>. The following examples all use bash, so if you run a different shell (if you don&#8217;t know, you probably aren&#8217;t) you may need to define environment variables differently.</p>
<h4>Braindead Proof of Concept (BPOC)</h4>
<p>Situation: You want to display an application running on a machine called <code>w00t</code> on another machine, called <code>bling</code>. There&#8217;s an X11 server running on bling, but it&#8217;s not configured to listen on any TCP socket. DNS is properly setup, so if you ping w00t from bling, you get replies from bling&#8217;s IP, and vice versa.</p>
<ol>
<li>On bling, find the domain socket of bling&#8217;s X11 server. Have a look in <code>/tmp/.X11-unix/</code>. The socket&#8217;s name usually reflects its X server display number (which you can determine by running <code>echo $DISPLAY</code> in an xterm).</li>
<li>On bling, run something along the lines of<br />
<code>socat TCP-LISTEN:6066 UNIX-CONNECT:/tmp/.X11-unix/X0</code><br />
This will open up TCP port 6066 on all of bling&#8217;s network interfaces, connecting it to the Unix domain socket of the X server.</li>
<li>In an xterm on bling, run <code>xhost +</code>. You have now opened up your X11 server to the whole wide world, a silly thing to do. Anyone with access to the TCP socket can now read your keystrokes, read your window contents, click your mouse buttons&#8230;</li>
<li>In an xterm on w00t, run <code>DISPLAY="bling:66" xclock</code>. You may have noticed that 66 = 6066 &#8211; 6000 and indeed, by convention the TCP port number for a certain display is its display number + 6000. Anyhow&#8230;. yay, a clock! It&#8217;s displayed on bling, but running on w00t.</li>
</ol>
<h4>Improvements</h4>
<ul>
<li>You may have noticed that in the BPOC, you can use the display on bling only once. <code>socat</code> will allow only one client, and will exit once that client exits. In some situations, you may consider that a feature (it&#8217;s a one-time access grant), but in others you may not. If you want a reusable TCP socket, run something along the lines of<br />
<code>socat TCP-listen:6066,fork,reuseaddr UNIX-CONNECT:/tmp/.X11-unix/X0</code> which forks off a socat process for every TCP connection.
</li>
<li>You may not want to expose a TCP socket on all interfaces. Maybe you only want to expose a socket on the LAN interface, or on the localhost interface (and wrap the packets in an SSH tunnel). Well, you can, using the &#8216;bind&#8217; option:<br />
<code>socat TCP-LISTEN:6066,bind=localhost UNIX-CONNECT:/tmp/.X11-unix/X0</code><br />
Now tunnel it over SSH. On w00t, run <code>ssh -L 6011:localhost:6023 bling</code>. Now localhost:6011 on woot is actually localhost:6023 on bling which is actually /tmp/.X11-unix/X0 on bling. So on w00t you can  start an xclock with its display on bling by running <code>DISPLAY="localhost:11" xclock</code>.
</li>
<li><code>xhost +</code> from the BPOC is braindead indeed. There are a couple things you could have done instead, there are good ways of tightening up your authorization scheme.
<ul>
<li>First off, you don&#8217;t really need to run <code>xhost +</code> if you properly set up X11 cookies, which you should. <a href="http://tldp.org/HOWTO/Remote-X-Apps-6.html#ss6.2">Here are some examples on using the xauth scheme</a>, but take note: <code>xauth generate</code> will probably not work on recent X11 releases since the XSECURITY extension is disabled by default. Just use the same cookies on the client and the server.
</li>
<li>Run <code>xhost +w00t</code>. That&#8217;s host-based authentication, which is stupid, but not as stupid as no authorization at all. Any user on w00t can now connect.
</li>
<li>Suppose that on bling (of course!) you&#8217;d run <code>xhost +SI:localuser:theuser</code> with &#8216;theuser&#8217; being the userID of the unix-user running the socat instance. Now from the point of view of the X server, any client connecting through socat will be coming from &#8216;theuser&#8217; and will therefore be allowed access. Entertaining, but not much different from just running <code>xhost +</code>. It is something to keep in mind though! Many distros by default add the unix-user that started the X server to the authorization list. That user does not need a cookie. If you run socat as that user you will have the effect of running <code>xhost +</code> even if you run <code>xhost -</code>.
</li>
<li>Just run a nested X11 server, such as Xnest or Xephyr. This way you put untrusted users in a sandbox, preventing them from snooping your keyboard and windows. It&#8217;s the X11 equivalent of a chroot.
</li>
</ul>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://smorgasbord.gavagai.nl/2010/01/socat-access-your-x-servers-domain-socket-over-tcp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

