LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-08-2004, 01:42 AM   #1
vdogvictor
Member
 
Registered: Feb 2004
Distribution: Arch
Posts: 498

Rep: Reputation: 31
Can't run gui applications as root


This one has me stumped. I am on SuSE 9.0 Pro w/ KDE Everything works fine as root and as a user. The problems happen when I am logged on as a user and su - to root from the terminal and try to run a gui-application from the command line. Each app gives me a different error, but they all relate to "not able to open display" How can I run a gui-app as root when logged in as a user?
 
Old 07-08-2004, 02:31 AM   #2
sbogus
Member
 
Registered: May 2004
Location: Germany, Munich
Distribution: SuSE Pro Releases 7.3, 9.0, CentOS 4.0, Kubuntu 6.0x
Posts: 103

Rep: Reputation: 15
Very easy
You need to tell your "normal user" XServer to allow connections from other users, which usually is not the case.

One possible way is to tell from a console, logged in as normal user this:
xhost + localhost

Then when you make su - in a terminal/console, type in this:
export DISPLAY=:0.0

Now you can run your GUI-application as root.

Kind regards,
sbogus
 
Old 08-12-2004, 03:00 PM   #3
g4c9z
Member
 
Registered: May 2004
Location: Canada
Distribution: Gentoo
Posts: 36

Rep: Reputation: 15
Actually, I had it working before by running:

xhost +

instead of:

xhost + localhost

Just so you know, "xhost +" removes all security restrictions for who can create windows on your desktop, while "xhost + localhost" supposedly allows anyone from the same computer to create windows on your desktop, according to "man xhost".

With my old setup of "xhost +", it was working but giving error messages only when root ran GUI applications. Now, on your suggestion, I added localhost and it gives error messages and doesn't even run the application. The error messages I got when trying to run Konqueror was:

Xlib: connection to ":0.0" refused by server
Xlib: Invalid MIT-MAGIC-COOKIE-1 key
konqueror: cannot connect to X server :0.0

Are you sure (all) you're supposed to do is run "xhost + localhost" as the normal user and set DISPLAY=:0.0 for root?
 
Old 08-12-2004, 03:05 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Try without the space between the + and the localhost

Using "xhost +" is BAD practice.

Ideally you'd try to avoid using it at all, and use local
ssh with X forwarding instead.

ssh -X root@localhost "konqueror"

;)


Cheers,
Tink
 
Old 08-12-2004, 04:20 PM   #5
g4c9z
Member
 
Registered: May 2004
Location: Canada
Distribution: Gentoo
Posts: 36

Rep: Reputation: 15
Quote:
Try without the space between the + and the localhost
Tried it, no difference.
 
Old 08-12-2004, 04:22 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Try with an
export DISPLAY=localhost:0.0
(or, it you happened to use (t)csh for some
strange reason)
setenv DISPLAY localhost:0.0


Cheers,
Tink
 
Old 08-12-2004, 04:39 PM   #7
g4c9z
Member
 
Registered: May 2004
Location: Canada
Distribution: Gentoo
Posts: 36

Rep: Reputation: 15
Quote:
Try with an
export DISPLAY=localhost:0.0
Didn't work, but now there's a different error message, and it sits there for a few seconds before printing it. The new error is:

Code:
konqueror: cannot connect to X server localhost:0.0
Could you explain what all this localhost:0:0, :0.0, etc. means? (I like to understand everything)
 
Old 08-12-2004, 04:44 PM   #8
g4c9z
Member
 
Registered: May 2004
Location: Canada
Distribution: Gentoo
Posts: 36

Rep: Reputation: 15
By the way, Tinkster, I just tried your ssh suggestion and it gave the following error message:

ssh: connect to host localhost port 22: Connection refused

I don't know if that has anything to do with anything.

(Did you notice how error messages in Linux are often meant to be understood only by the person who wrote them? )
 
Old 08-12-2004, 05:06 PM   #9
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
connection refused can mean that
a) sshd isn't running
b) sshd is configured to deny logins from root
c) localhost is not in /etc/hosts
d) a firewall isn't set-up correctly


Cheers,
Tink
 
Old 08-12-2004, 08:46 PM   #10
g4c9z
Member
 
Registered: May 2004
Location: Canada
Distribution: Gentoo
Posts: 36

Rep: Reputation: 15
Yeah, it's a). My /etc/hosts does have localhost set up correctly.

Here's something to think about: why do I have to check which of the 4 alternatives is the case? Why can't the program tell me?

People usually think of user-friendliness as meaning an intuitively designed graphical user interface. But specific error messages are a very important part of a user-friendly program too, and they're a part that's usually ignored.
 
Old 08-12-2004, 09:04 PM   #11
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Because (in this particular case) the program is
designed to be run against remote machines,
and it's in the nature of that that it can't determine
the reason for the failure to connect ;}


Cheers,
Tink
 
Old 08-12-2004, 09:19 PM   #12
g4c9z
Member
 
Registered: May 2004
Location: Canada
Distribution: Gentoo
Posts: 36

Rep: Reputation: 15
Actually, yeah, I see what you mean for this case. I think it still could have a special case for when you're trying to connect to this computer - it could do some extra checks to see what's wrong. But then the program would be getting TOO smart I suppose.

Still, how about if it had a nice error message like this:

ssh: could not connect to port 22 of the computer "localhost" because "localhost" wouldn't let me. This may have a variety of causes but is probably the fault of "localhost".

Last edited by g4c9z; 08-12-2004 at 09:20 PM.
 
Old 08-12-2004, 09:45 PM   #13
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Too chubby ... maybe with side-effects like in
windows ;)




Cheers,
Tink


P.S.: If you make a program idiot-proof only
idiots will use it ;0
 
Old 08-13-2004, 01:21 PM   #14
g4c9z
Member
 
Registered: May 2004
Location: Canada
Distribution: Gentoo
Posts: 36

Rep: Reputation: 15
I discovered a way to make it work; instead of:

xhost +localhost

I ran:

xhost +local:

See "man xhost" for more on this.

Could this in fact be the correct way to enable root to run windows on your GUI?
 
Old 08-13-2004, 03:56 PM   #15
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
ssh would be the safest easy way.
If the machine is multiuser people could
play tricks on you by opening stuff in
your session if you have xhost +local
(or localhost, for that matter) enabled.

I have seen scripts (run by root) that
modify the targets .Xauthority file, which
will give root the right to open X apps
in the target users session.

xhost really is a kludge.


Cheers,
Tink

.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't run gui (X) programs as root user nazdrowie Linux - General 25 12-02-2008 01:24 AM
How to run GUI program as root shadkong Slackware 8 09-20-2005 02:24 PM
Unable to run a GUI app as root using su? vharishankar Linux - General 7 05-25-2005 08:08 AM
Best java ide for gui applications xiang83 Programming 3 01-27-2005 01:59 PM
Cannot run X applications as root jplev22 Slackware 8 02-15-2004 10:39 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:03 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