]> www.wagner.pp.ru Git - sites/home_page.git/blob - hints/xauth.html
Ссылка на html Ясмины
[sites/home_page.git] / hints / xauth.html
1 <HTML><HEAD>
2 <META HTTP-EQUIV="Content-Type" "text/html; charset=utf-8">
3 <TITLE>Права доступа к X серверу</TITLE>
4 <META NAME="description" CONTENT="Как добиться чтобы программу,
5 запущенную на другом хосте или от имени другого пользователя, пустили
6 нарисовать окошко на вашем дисплее"> 
7 </HEAD><BODY>
8 <H1>Права доступа к X-серверу</h1>
9
10 Have you ever been troubled with X magic cookie authenification, trying
11 to start X-basing tool as root, when X display belongs to you, as
12 ordinary user? I have, and decide to write stupid shell script to get
13 around this problem. Note, that root can read your .Xauthority file.
14 So, if you want to su to another user, you'll need more elaborate solution.
15 <P>
16 Of course before you start to need this, you need to enable <B>xauth</B>
17 style authenification. If you are on that stage, read
18 <A HREF="http://r8h.cs.man.ac.uk:8000/tcl/secure.html">Quick quide</A>
19 by
20 <A HREF="http://r8h.cs.man.ac.uk:8000/"> Donal K. Fellows</A>.
21
22 <P>
23 There is several solutions  
24 <UL>
25 <LI>type <PRE>
26     <b>xsu</b> command 
27    </PRE>
28 <p>
29    from xterm and then type password
30    Note that <B>xsu</B> doesn't support all options of <B>su</B>
31 </p>
32 <pre>
33 #!/bin/sh
34 # @(#) xsu - executes command as root in X11 with enabled autenification
35 # command should be passed as one argument
36 if [ -z &quot;$DISPLAY&quot; ]
37 then
38   echo &quot;You are not running X11. Use plain su!&quot;
39   exit 1
40 fi
41 if [ -z &quot;$1&quot; ]
42 then
43   command=$SHELL
44 else 
45   command=&quot;$@&quot;
46 fi
47 su -c &quot;xauth merge `eval echo ~$USER`/.Xauthority;$command&quot;
48 </pre>
49 <LI> add following code to your root <B>.bashrc</B> file,
50      and you would automatically recieve access to X server, when
51      you are typing <CODE>su</CODE> (but not <CODE>su -</CODE>)
52      <PRE>
53 # cut from root's .bashrc
54
55 if [ -n $DISPLAY ] && [  "$USER" != root ]
56 then
57   XAUTHORITY=`eval echo ~$USER`/.Xauthority
58   export XAUTHORITY
59 fi
60  
61   </PRE>
62   
63 <LI>Add <b>wmsu</b> command
64   
65   in your window manager menu, and you'll be presented by small window
66   to type password in before specified command would be run as root.
67 <pre>
68 #!/bin/sh
69 # @(#) xsu - executes command as root in X11 with enabled autenification
70 # command should be passed as one argument
71 if [ -z &quot;$DISPLAY&quot; ]
72 then
73   echo &quot;You are not running X11. Use plain su!&quot; >&2
74   exit 1
75 fi
76 if [ -z &quot;$1&quot; ]
77 then
78   echo &quot;wmsu: no command supplied&quot; >&2
79   exit 1
80 else 
81   command=$@
82 fi
83 xterm -geometry=20x2 -title &quot;Type password&quot; -e su -c &quot;\&quot;xauth merge `eval echo ~$USER`/.Xauthority;$command\&quot;&quot;
84
85 </pre>
86 </UL>
87 <P>
88 If you often need to login to remote machines and start X programs from
89 there, you might want to use <A HREF="../software/unix/foreign_xterm.html">foreign_xterm</A>
90 script, which transfers correct authenification info to remote machine
91 and runs xterm or specified command from there via <B>rsh</B>. 
92 It passes  arguments
93 to <B>rsh</B> and invoked command, so things like 
94 <PRE>
95 foreign_xterm -l somebody somehost -e mc
96 </PRE>
97 would work. If called after name <tt>foreign_xapp</tt> it doesn't spawn xterm - just transfer authorization token and start desired command setting right value for DISPLAY variable.
98 <P>
99 Note, that if you use <A HREF="http://www.openssh.org">ssh</A>, you don't need 
100 such tricks - it does them for you. But, if you are using some other daemons such as Network Audio or floppyd you might need it anyway 
101 </BODY>
102 </HTML>