Of course before you start to need this, you need to enable xauth style authenification. If you are on that stage, read Quick quide by Donal K. Fellows.
There is several solutions
xsu command
from xterm and then type password Note that xsu doesn't support all options of su
#!/bin/sh # @(#) xsu - executes command as root in X11 with enabled autenification # command should be passed as one argument if [ -z "$DISPLAY" ] then echo "You are not running X11. Use plain su!" exit 1 fi if [ -z "$1" ] then command=$SHELL else command="$@" fi su -c "xauth merge `eval echo ~$USER`/.Xauthority;$command"
su
(but not su -
)
# cut from root's .bashrc if [ -n $DISPLAY ] && [ "$USER" != root ] then XAUTHORITY=`eval echo ~$USER`/.Xauthority export XAUTHORITY fi
#!/bin/sh # @(#) xsu - executes command as root in X11 with enabled autenification # command should be passed as one argument if [ -z "$DISPLAY" ] then echo "You are not running X11. Use plain su!" >&2 exit 1 fi if [ -z "$1" ] then echo "wmsu: no command supplied" >&2 exit 1 else command=$@ fi xterm -geometry=20x2 -title "Type password" -e su -c "\"xauth merge `eval echo ~$USER`/.Xauthority;$command\""
If you often need to login to remote machines and start X programs from there, you might want to use foreign_xterm script, which transfers correct authenification info to remote machine and runs xterm or specified command from there via rsh. It passes arguments to rsh and invoked command, so things like
foreign_xterm -l somebody somehost -e mcwould work. If called after name foreign_xapp it doesn't spawn xterm - just transfer authorization token and start desired command setting right value for DISPLAY variable.
Note, that if you use ssh, you don't need 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