{"id":327,"date":"2007-09-15T09:29:17","date_gmt":"2007-09-15T07:29:17","guid":{"rendered":"http:\/\/tronche.com\/blog\/less-technical\/uncategorized\/2007\/09\/automatically-forward-x-connections-ubuntu\/"},"modified":"2007-09-15T09:29:17","modified_gmt":"2007-09-15T07:29:17","slug":"automatically-forward-x-connections-ubuntu","status":"publish","type":"post","link":"https:\/\/tronche.com\/blog\/2007\/09\/automatically-forward-x-connections-ubuntu\/","title":{"rendered":"Automatically forward X connections (Ubuntu)"},"content":{"rendered":"<p>I have the habit of having one user per function (for example customer care is a user, dev is a user and so on). So I&#8217;m continuously jumping from one Unix user to another.<\/p>\n<p>The desktop, however, is one and only one, so I need to forward X authentication from user to user (I&#8217;ll explain in a minute).<\/p>\n<p>In the Redhat days, that wasn&#8217;t such a problem, because the system was doing it for me. However, in switching to Ubuntu, I was surprised this feature didn&#8217;t hold.<\/p>\n<p>I give you an example to be more concrete. Let&#8217;s say I&#8217;ve logged into the desktop as user tof. I can do this:<\/p>\n<p><!--more--><br \/>\nI have the habit of having one user per function (for example customer care is a user, dev is a user and so on). So I&#8217;m continuously jumping from one Unix user to another.<\/p>\n<p>The desktop, however, is one and only one, so I need to forward X authentication from user to user (I&#8217;ll explain in a minute).<\/p>\n<p>In the Redhat days, that wasn&#8217;t such a problem, because the system was doing it for me. However, in switching to Ubuntu, I was surprised this feature didn&#8217;t hold.<\/p>\n<p>I give you an example to be more concrete. Let&#8217;s say I&#8217;ve logged into the desktop as user tof. I can do this:<br \/>\n<!--break--><\/p>\n<pre>\r\ntof@machine:~$ xload &\r\n<\/pre>\n<p>And xload appears on the screen. Nothing sexy. Now, I can switch to user dev, which I do via the user root (so I only have to remember the root password, not every user&#8217;s, but I still need to give one password):<\/p>\n<pre>\r\ntof@machine:~$ su -\r\nPassword: ********\r\nroot@machine:~# xload &\r\n<\/pre>\n<p>And it&#8217;s not working.<\/p>\n<p>The reasons are<br \/>\n* the DISPLAY environment variable must be exported to root&#8217;s environment and<br \/>\n* the credentials must be exported as well. Credentials are a mean to prevent another user from spying what you&#8217;re doing, notably your passwords, by listening to your interactions with the X server.<\/p>\n<p>There&#8217;s a PAM module that can do this automatically for you, but strangely, it isn&#8217;t enabled by default in Ubuntu 7 (&#8220;Feisty Fawn&#8221;).<\/p>\n<p>So we&#8217;ll do this. In \/etc\/pam.d\/su we add:<\/p>\n<pre>\r\nsession optional        \/lib\/security\/pam_xauth.so\r\n<\/pre>\n<p>Then we try again:<\/p>\n<pre>\r\ntof@machine:~$ su -\r\nPassword: ********\r\nroot@machine:~# xload &\r\n<\/pre>\n<p>This time it works ! But we aren&#8217;t at the end of the story yet. Now we go to the crm user:<\/p>\n<pre>\r\nroot@machine:~# su - crm\r\ncrm@machine:~$ xload&\r\n<\/pre>\n<p>That time it doesn&#8217;t work. The reason is pam_xauth itself has a small security mechanism, such as when you go from root to another user, this user must be explicitly declared for pam_xauth to forward the X context. So we must add a ~root\/xauth directory with an &#8220;export&#8221; file, listing the crm user (alternatively, we could disable this mechanism, but a little security doesn&#8217;t hurt).<\/p>\n<p>As root, we type:<\/p>\n<pre>\r\nroot@machine:~# cd\r\nroot@machine:~# mkdir xauth\r\nroot@machine:~# chmod 700 xauth # A little privacy here\r\nroot@machine:~# echo crm >> xauth\/export\r\nroot@machine:~# su - crm\r\ncrm@machine:~$ xload&\r\n<\/pre>\n<p>That&#8217;s it !<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>I have the habit of having one user per function (for example customer care is a user, dev is a user and so on). So <a class=\"mh-excerpt-more\" href=\"https:\/\/tronche.com\/blog\/2007\/09\/automatically-forward-x-connections-ubuntu\/\" title=\"Automatically forward X connections (Ubuntu)\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-327","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/tronche.com\/blog\/wp-json\/wp\/v2\/posts\/327","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tronche.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tronche.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tronche.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tronche.com\/blog\/wp-json\/wp\/v2\/comments?post=327"}],"version-history":[{"count":0,"href":"https:\/\/tronche.com\/blog\/wp-json\/wp\/v2\/posts\/327\/revisions"}],"wp:attachment":[{"href":"https:\/\/tronche.com\/blog\/wp-json\/wp\/v2\/media?parent=327"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tronche.com\/blog\/wp-json\/wp\/v2\/categories?post=327"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tronche.com\/blog\/wp-json\/wp\/v2\/tags?post=327"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}