LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   How to Run an Application as root without a log off? (https://www.linuxquestions.org/questions/linux-software-2/how-to-run-an-application-as-root-without-a-log-off-22111/)

shassouneh 05-29-2002 06:48 PM

How to Run an Application as root without a log off?
 
Dear All,
I know this sounds like a question that has been asked many a times before, but there is a serious twist in it, so please humor me and reas on.

Firstly, the set up:

Distro: SuSE Linux 7.3 Professional
kernel: 2.4.10-Gmbh (yes its old, working on recompiling the new one)
Video Card: Nvidia GeForce 2 MX 400 AGP 4x 64MB

Things to know before describing the problem:
I have just downloaded the latest video drivers from Nvidia.com and installed them for my distro (SuSE 7.3)


Now the problem:
I wish to be able to run an application as root without having to log off /log back on and/or restart the X server.
I tried using su - and it logged me in fine, but when I try to launch an application I receive the following error:

Gtk-WARNING **: cannot open display:


Here are examples to illustrate this better:

Example 1: (quoted and bolded for readability_
Quote:


samer@suse_or_bust:~> su -
Password:
suse_or_bust:~ # xcdroast

Gtk-WARNING **: cannot open display:
suse_or_bust:~ #

Example 2: (quoted and bolded for readability)
Quote:



samer@suse_or_bust:~> su -
Password:
suse_or_bust:~ # xmms

** CRITICAL **: Unable to open display
suse_or_bust:~ #


Please reply if you can help. Your replies are well appreciated before hand :)

verigoth 05-29-2002 08:40 PM

here's what you need to do:

# su -
Password:
# export PATH=$PATH:/usr/X11R6/bin:/opt/gnome/bin:/opt/kde/bin (or where kde/gnome are installed)
# export DISPLAY=localhost:0
# xmms

verigoth

shassouneh 05-30-2002 02:50 PM

Thanx for the reply. I have tried the steps you mentioned and I still got an error. Here is the run, bolded and quoted for readability

Quote:


samer@suse_or_bust:~> su -
Password:
suse_or_bust:~ # export PATH=$PATH:/usr/X11R6/bin:/opt/gnome/bin:/opt/kde/bin
suse_or_bust:~ # export DISPLAY=localhost:0
suse_or_bust:~ # xcdroast
Xlib: connection to "localhost:0.0" refused by server
Xlib: Invalid MIT-MAGIC-COOKIE-1 key

Gtk-WARNING **: cannot open display: localhost:0
suse_or_bust:~ #

Note that export PATH seemed to have worked (as no errors where shown).

Please reply if you can help.

Thanx for the replies beforehand :)

acid_kewpie 05-30-2002 03:43 PM

well that's nothing to do with logging off or anything, you simply haven't allowed external access to your X sessions. run "xhost +root" and try again.

verigoth 05-30-2002 06:50 PM

damn...new i forgot something ;) thanks

verigoth

shassouneh 05-30-2002 07:58 PM

Nope, Still no can do. Same error message. Here is a test run for you to see my results (bolded and quoted for readability)

Quote:


samer@suse_or_bust:~> su -
Password:
suse_or_bust:~ # export PATH=$PATH:/usr/X11R6/bin:/opt/gnome/bin:/opt/kde/bin
suse_or_bust:~ # export DISPLAY=localhost:0
suse_or_bust:~ # xhost +root
Xlib: connection to "localhost:0.0" refused by server
Xlib: Client is not authorized to connect to Server
xhost: unable to open display "localhost:0"
suse_or_bust:~ # xmms
Xlib: connection to "localhost:0.0" refused by server
Xlib: Client is not authorized to connect to Server

** CRITICAL **: Unable to open display
suse_or_bust:~ #

Also, If i try to do the xhost +root first, it still doesn't work. For example:
Quote:


samer@suse_or_bust:~> su -
Password:
suse_or_bust:~ # xhost +root
xhost: unable to open display ""
suse_or_bust:~ #

Can anybody please help? This is driving me nutts!

linuxcool 05-31-2002 12:23 AM

Try running xhost +root before you execute su -. If +root doesn't work, try +localhost.

acid_kewpie 05-31-2002 10:13 AM

well naturally it's the person that OWNS the X server that is the only one who can allow external connections...

shassouneh 05-31-2002 12:59 PM

hmm, Still not making sense. As user "samer" I gave localhost access to the X server. Now as root it STILL complains about connectiong to the XServer. Here is the run, bolded and quoted for readability

Quote:


samer@suse_or_bust:~> xhost +localhost
localhost being added to access control list
samer@suse_or_bust:~> export PATH=$PATH:/usr/X11R6/bin:/opt/gnome/bin:/opt/kde/bin
samer@suse_or_bust:~> export DISPLAY=localhost:0
samer@suse_or_bust:~> su -
Password:
suse_or_bust:~ # kedit
kedit: cannot connect to X server
suse_or_bust:~ #


shassouneh 05-31-2002 01:05 PM

For Future Reference, I got this to work. I'm sure someone else may have similar problems, so here is a Qui Guide to What I did
1.) Open up a a Konsole/bash prompt.
2.) type in "xhost +localhost" without the quotes. This should say something like: "localhost being added to access control list"
3.)Log in as root with "su -" and type in your password
4.)type in "export PATH=$PATH:/usr/X11R6/bin:/opt/gnome/bin:/opt/kde/bin" without the quotes. You may need to change this if you installed your KDE in a different directory
5.)type in "export DISPLAY=localhost:0"
6.)Now you can run programs as root without a log off!

NOTE: This will NOT work if you simply save the steps to some file and give it executable permissions. If anybody knows a way to get it to work as such, please let us Know. I tried it that way and it gave me a
Quote:


** CRITICAL **: Unable to open display


acid_kewpie 05-31-2002 01:13 PM

does the file HAVE to be called graxs? :)
the path statement should not be related to your situation, and should be done in a different scope to the system. if you need executables in there you should add it to roots path. And of course using su in a script file is a pretty daft thing to do really.

You should also be able to creaet a permanent X host access file, as defined in "man xhost" which will make these changes permenent, rather than using a redundant script each time to do exactly the same thing.

shassouneh 05-31-2002 01:16 PM

Acid, I edited my message above. Frankly I'm the only user using this machine, and I don't want to keep logging off/on to access a program as root. I tried doing the executable file for the heck of it and It didn't work as mentioned above. If you know how please explain how I can generate such a script to make thkings permenant and allow running a program as root on the fly. Thanx for all the replies everyone. They are much appreciated.

acid_kewpie 05-31-2002 01:31 PM

well putting aside the issue that i don't like the idea, there's no simple way really... running su will start a new shell, and the remaining commands will not be executed until you exit that shell. a way around the issue would be to go down the line of something as equally icky as

xhost +whoever/wherever
su -c 'set something; something else; xterm'

that should then open a x terminal ready for use as root.. but it's not really too nice.

shassouneh 05-31-2002 02:15 PM

I see. I guess I can just stick to copy/paste and copy the exports as mentioned on this post, LOL. I understand your concern from the viewpoint of security, and I kinda also don't like doing it since Im not going to be always running on my machine. However, it is a quick and dirty way to do things.
For security puposes, I'll type in (or paste in) everything myself.

By The way, I tried doing it without the export Path..... and just doing the export DIPLAY= .... thingy and it worked too :)

verigoth 06-02-2002 02:11 PM

just to clarify my reasoning: in Slackware (not sure about any other distro), when you su to root, your path is limited to /bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin. if you wanted to run any executable not in any of those places you would have to change the path. not knowing where the application shassouneh wanted to run resided, i said to change the path.

verigoth


All times are GMT -5. The time now is 10:46 PM.