DebianThis forum is for the discussion of Debian Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
michael@debian:~$ su -
Password:
debian:~# gedit
(gedit:1242): Gtk-WARNING **: cannot open display:
debian:~# synaptic
(synaptic:1243): Gtk-WARNING **: cannot open display:
debian:~# kedit
kedit: cannot connect to X server
debian:~#
If I log as root from gdm i can run X applications, but not with 'su'.
That should get it working. If you are not logged in on an X session as that user then you will see an error when you log in as root from a console, because the user is not using X at the moment. The error can be ignored.
I wrote a little script to give root permission to run X programs:
Code:
#! /bin/sh
xhost local:root
xterm -T "Run X Programs as Root" -geometry 100x20 -e dialog --title \
"Run X Programs as Root" --msgbox "Root can now open X programs. \
Press enter to continue. . . ." 9 50
I have this script saved as the file runXroot in my /home directory. I made it executable with "chmod +x runXroot" On my KDE desktop, I created a link to open the application with the command "/home/matt/./runXroot" Now when I need to run a program as root, I just click on the button on my desktop. The script pops up a dialog that informs you that root now has permission.
Of course, the method above given by Stephen is easier and makes the change happen every time you log into X. However, some people may not want root to have permission to run X programs all the time.
Of course, the method above given by Stephen is easier and makes the change happen every time you log into X. However, some people may not want root to have permission to run X programs all the time.
It is not every time you log into X it would only give the person who is listed in the line permission to do so when using su in a console window to go to root so they have to have the root password anyways. If you have not logged into X as that person then it would not apply and this includes root at the console the normal users Xauthority who is listed would not exist.
Now I'm actually using Slackware 10.0 (I'm in a proccess of finding the "right" distro for me) and I have the exact problem.
I tried adding
Code:
export XAUTHORITY=/home/stephen/.Xauthority
to my .bashrc file but there are two problems:
1. I don't have .bashrc in my home dir (niether in root's homedir).
2. I created a .bashrc file and put this line in it, but it did not help. Actually, after adding this line in .bashrc I could no longer run X apps even when I was logged as root (gdm and gnome did load, however), so I removed this line.
I will try RunLevelZero's solution.
About Dead Parrot's solution, as I mentioned before I'm using slack10 right now and I have Xorg not XFree86, so I'm not totally sure what to do here:
Quote:
I did some digging and found several recommendations from Debian developers to use xauth instead of xhost. Here's one trick that sounds very nice (although, again, I haven't tried it myself): Create a file /etc/X11/Xsession.d/10xfree86-common_su and make it include these lines:
if [ -z "$XAUTHORITY" ]; then
XAUTHORITY=$HOME/.Xauthority
export XAUTHORITY
fi
Should I just replace '10xfree86-common_su' with '10xorg-common_su' - will it simply work? Worth a try I guess, don't think it will brake something (emphesize on think)
Did you remember to log out after making xauth changes? Also, did you check that you don't have any xhost entries in your startup files? I've been told that setting xhost overrides any xauth settings.
Edit:
If our suggestions don't seem to help, you can do some experimenting in xterm to find out whether any of these suggestions works at all. If one of the experiments described below works, you only need to figure out which startup file you need to use to execute this working solution. If none of these experiments will work, you must look for some other solution.
Before you start experimenting, remove all the changes you've made to the startup files (both in your home directory and in root user's directory). Then log out, login again, start X as usual, and launch xterm.
1.
$ xauth merge /home/your_user_name/.Xauthority
$ export DISPLAY=:0
$ su
# [launch X application as root user]
2.
$ export XAUTHORITY=/home/your_user_name/.Xauthority
$ su
# [launch X application as root user]
3.
$ xhost local:root
$ su
# [launch X application as root user]
4.
$ xhost +localhost
$ su
# [launch X application as root user]
Note: In xterm you can return from root user to normal user quickly by pressing simultaneously the hot key combination "Ctrl" and "d".
Last edited by Dead Parrot; 07-17-2004 at 04:51 PM.
Will work on Slackware as well as Debian to give root permission to open X programs. That is the command I have in the script posted above. In Slackware, it should be possible to add that command to a local startup script. You should try adding it to the .xsession file in the users directory to see if that works.
I need to login/out each time before I try each solution in xterm?
No need for that because you run the commands directly from xterm (and not from the startup files that are read during login). Just make sure you've removed any earlier xauth and xhost settings so that they don't interfere with your little experiments.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.