{"id":173,"date":"2006-08-10T07:10:34","date_gmt":"2006-08-10T13:10:34","guid":{"rendered":"http:\/\/blog.the-erm.com\/index.php\/archives\/173"},"modified":"2006-08-21T06:44:13","modified_gmt":"2006-08-21T12:44:13","slug":"pass-display-when-using-su-and-not-p","status":"publish","type":"post","link":"https:\/\/blog.the-erm.com\/?p=173","title":{"rendered":"Pass DISPLAY when using su and not -p"},"content":{"rendered":"<p>I was aggravated.  I recently switched distros, and by default su didn&#8217;t pass the DISPLAY variable, and when I used su -p it didn&#8217;t cd to their $HOME it cd to my home, the &#8216;parent&#8217; shell&#8217;s home.<\/p>\n<p><!--more--><\/p>\n<p>So I concentrated on other things.  Got my sound card set up,  Installed flash, mplayer, and quite a few other things.<\/p>\n<p>Then it was time.  It bothers you when that 1 little thing isn&#8217;t working right.<\/p>\n<p>su was my thing.<\/p>\n<p>After spending some time in chat rooms, and asking questions, I decided that google was the next best guess.  Honestly I thought the solution was something as simple as changing a line in some config file in \/etc.  I was wrong&#8230;.<\/p>\n<p>I found some <a href=\"https:\/\/www.linux-magazine.com\/issue\/53\/Gentoo_File_Manager.pdf\">obscure pdf file<\/a> that had most of the answers.<\/p>\n<p>From there I filled in the blanks.<\/p>\n<p>I added these lines<\/p>\n<h2>\/etc\/bash.bashrc<\/h2>\n<pre>\r\nalias su='suwrap.sh'\r\n\r\nif [ -e \"\/tmp\/.tmp.x.key\" ] \r\nthen\r\n\tTMP_KEY=`cat \/tmp\/.tmp.x.key`\r\n\tTMP_DISPLAY=`cat \/tmp\/.tmp.x.display`\r\n\tif [ -n \"$TMP_KEY\" ]\r\n\tthen\r\n\t\tif [ -n \"$TMP_DISPLAY\" ]\r\n\t\tthen\r\n\t\t\txauth merge \/tmp\/.tmp.x.key\r\n\t\t\texport DISPLAY=`cat \/tmp\/.tmp.x.display`\r\n\t\tfi\r\n\tfi\r\n\t# clean it up we don't want anyone else getting into the display\r\n\techo -n > \/tmp\/.tmp.x.key\r\n\techo -n > \/tmp\/.tmp.x.display\r\n\trm \/tmp\/.tmp.x.key -f &>\/dev\/null\r\n\trm \/tmp\/.tmp.x.display -f &>\/dev\/null\r\nfi\r\n<\/pre>\n<p>Then I wote a wrapper.<\/p>\n<h2>\/bin\/suwrap.sh<\/h2>\n<pre>\r\n#!\/bin\/sh\r\n\r\nif [ -n \"$DISPLAY\" ]\r\nthen\r\n\txauth extract \/tmp\/.tmp.x.key $DISPLAY\r\n\techo -n $DISPLAY > \/tmp\/.tmp.x.display\r\nelse \r\n\techo -n > \/tmp\/.tmp.x.key\r\n\techo -n > \/tmp\/.tmp.x.display\r\nfi\r\nchmod 777 \/tmp\/.tmp.x.key &>\/dev\/null\r\nchmod 777 \/tmp\/.tmp.x.display &>\/dev\/null\r\nif [ -n \"$*\" ]\r\nthen\r\n\tsu \"$*\"\r\nelse \r\n\tsu\r\nfi\r\necho -n '' > \/tmp\/.tmp.x\r\necho -n '' > \/tmp\/.tmp.x.display\r\nrm \/tmp\/.tmp.x -f &>\/dev\/null\r\nrm \/tmp\/.tmp.x.display -f &>\/dev\/null\r\n\r\n\r\n<\/pre>\n<p>See that wasn&#8217;t that hard was it?<\/p>\n<p>I&#8217;ve run a few tests and su -c &#8220;make install&#8221; works fine.  As well as su -c &#8216;kate&#8217;<br \/>\nSo I now have my display, and I can run whatever I want in X without having to add su -p and have it mess up my $USER and $HOME variables.<\/p>\n<p>It might seem a little stupid to try and remove, and echo to it twice, but seriously &#8230; do you want to take any chances?<\/p>\n<p>I&#8217;m not sure if this is really secure, but who knows, it works.<\/p>\n<p>Erm<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was aggravated. I recently switched distros, and by default su didn&#8217;t pass the DISPLAY variable, and when I used su -p it didn&#8217;t cd to their $HOME it cd to my home, the &#8216;parent&#8217; shell&#8217;s home.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,24,9,10,8,5,1],"tags":[],"class_list":["post-173","post","type-post","status-publish","format-standard","hentry","category-insanity","category-life-stories","category-linux","category-linux-2","category-tech","category-things-that-get-me-mad","category-happy"],"_links":{"self":[{"href":"https:\/\/blog.the-erm.com\/index.php?rest_route=\/wp\/v2\/posts\/173","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.the-erm.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.the-erm.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.the-erm.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.the-erm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=173"}],"version-history":[{"count":0,"href":"https:\/\/blog.the-erm.com\/index.php?rest_route=\/wp\/v2\/posts\/173\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.the-erm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=173"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.the-erm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=173"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.the-erm.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}