LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices


Reply
  Search this Thread
Old 07-15-2004, 05:18 PM   #1
michaely
LQ Newbie
 
Registered: May 2004
Location: Israel
Distribution: n/a
Posts: 14

Rep: Reputation: 0
Can't run X apps as root


Code:
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'.

Last edited by michaely; 07-15-2004 at 05:23 PM.
 
Old 07-15-2004, 05:50 PM   #2
fur
Member
 
Registered: Dec 2003
Distribution: Debian, FreeBSD
Posts: 310

Rep: Reputation: 35
Just use sudo instead.
 
Old 07-15-2004, 06:27 PM   #3
RunLevelZero
Member
 
Registered: Jun 2004
Distribution: Debian
Posts: 46

Rep: Reputation: 15
Try this

I use this in my .bashrc file

" xauth merge /home/username-of-non-root-user/.Xauthority "

" export DISPLAY=:0 "

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.
 
Old 07-16-2004, 01:03 PM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
I just got a nice tip from Dead Parrot that solves this problem nicely. Check it out in my thread here:
http://www.linuxquestions.org/questi...hreadid=204095
 
Old 07-16-2004, 01:38 PM   #5
HappyTux
Senior Member
 
Registered: Mar 2003
Location: Nova Scotia, Canada
Distribution: Debian AMD64
Posts: 4,170

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally posted by David the H.
I just got a nice tip from Dead Parrot that solves this problem nicely. Check it out in my thread here:
http://www.linuxquestions.org/questi...hreadid=204095
Another easy way to do it is too put this in your /root/.bashrc.

Code:
# Allows me to run an X program as root
export XAUTHORITY=/home/stephen/.Xauthority
You would of course change the line to your user name.
 
Old 07-16-2004, 06:17 PM   #6
m_yates
Senior Member
 
Registered: Aug 2003
Location: Upstate
Distribution: Debian, Mint, Mythbuntu
Posts: 1,249

Rep: Reputation: 101Reputation: 101
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.

Last edited by m_yates; 07-16-2004 at 06:28 PM.
 
Old 07-16-2004, 06:46 PM   #7
HappyTux
Senior Member
 
Registered: Mar 2003
Location: Nova Scotia, Canada
Distribution: Debian AMD64
Posts: 4,170

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally posted by m_yates


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.
 
Old 07-17-2004, 04:37 AM   #8
michaely
LQ Newbie
 
Registered: May 2004
Location: Israel
Distribution: n/a
Posts: 14

Original Poster
Rep: Reputation: 0
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)
 
Old 07-17-2004, 05:29 AM   #9
Dead Parrot
Senior Member
 
Registered: Mar 2004
Distribution: Debian GNU/kFreeBSD
Posts: 1,597

Rep: Reputation: 46
michaely:

If you're the only user of your computer, you should try this

# ln -fs /home/your_username/.Xauthority /root/.Xauthority

The more complicated solutions are only needed for multiuser computers.
 
Old 07-17-2004, 11:13 AM   #10
michaely
LQ Newbie
 
Registered: May 2004
Location: Israel
Distribution: n/a
Posts: 14

Original Poster
Rep: Reputation: 0
I just tried it, and restarted X, but no good... same problem.

edit: Tried also RunLevelZero's solution, no good either :\

Last edited by michaely; 07-17-2004 at 11:20 AM.
 
Old 07-17-2004, 11:42 AM   #11
Dead Parrot
Senior Member
 
Registered: Mar 2004
Distribution: Debian GNU/kFreeBSD
Posts: 1,597

Rep: Reputation: 46
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.
 
Old 07-17-2004, 04:26 PM   #12
m_yates
Senior Member
 
Registered: Aug 2003
Location: Upstate
Distribution: Debian, Mint, Mythbuntu
Posts: 1,249

Rep: Reputation: 101Reputation: 101
The command:
Code:
xhost local:root
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.
 
Old 07-18-2004, 04:03 AM   #13
michaely
LQ Newbie
 
Registered: May 2004
Location: Israel
Distribution: n/a
Posts: 14

Original Poster
Rep: Reputation: 0
Dead Parrot, I need to login/out each time before I try each solution in xterm?
 
Old 07-18-2004, 04:47 AM   #14
Dead Parrot
Senior Member
 
Registered: Mar 2004
Distribution: Debian GNU/kFreeBSD
Posts: 1,597

Rep: Reputation: 46
Quote:
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SuSE 10, KDE 3.4: OpenGL apps only work when run as root pschoenb Linux - Software 1 11-10-2005 01:43 PM
Can U Run MS apps in MEPIS ? sgliggett MEPIS 5 07-02-2005 05:38 PM
can't run x apps iomari Linux - General 2 11-22-2004 02:00 AM
Using root in X, how to run apps as a usr ? Dark Carnival Linux - Security 6 05-25-2004 03:06 PM
run windows apps sentme_mail Linux - Newbie 4 09-08-2002 07:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian

All times are GMT -5. The time now is 07:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration