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 > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 03-31-2005, 01:28 PM   #1
chbin
Member
 
Registered: Mar 2005
Distribution: slackware-current
Posts: 379

Rep: Reputation: 31
Gvim as root in a users X


I never start X as root. I'm always running as just a regular user. I would like to start up gvim as root in this regular users X session. Is this possible? When I su to root from in an xterm shell and try to start gvim I get the expected result: Cannot open up Display. Of course because root has no display session running. I was thinking root can do anything and there should be a way to barge in on someone elses X session?
 
Old 03-31-2005, 01:59 PM   #2
ror
Member
 
Registered: May 2004
Distribution: Ubuntu
Posts: 583

Rep: Reputation: 33
Is it not possible to specify the display as 0:0 or whatever?
 
Old 03-31-2005, 02:20 PM   #3
chbin
Member
 
Registered: Mar 2005
Distribution: slackware-current
Posts: 379

Original Poster
Rep: Reputation: 31
Well after exporting the two shell variable it works.

export DISPLAY=:0.0"
export XAUTHORITY="/home/slack/Xauthority.

Hmm, I wonder if /root had an Xauthority file I could have used that instead of the one in /home/slack? Don't think so. It is probably used to give authority to the session like it says in its name
 
Old 03-31-2005, 02:20 PM   #4
cavalier
Member
 
Registered: Feb 2005
Location: Denver, CO
Distribution: Slack 12, tweaked just so (though I'm also a fan of Ubuntu)
Posts: 198
Blog Entries: 1

Rep: Reputation: 30
Yes, you sure can.

First, before you su to root, make sure that you execute "xhost +hostname" in the shell as your non-privileged user.

Then, once you've become root, you can "export DISPLAY=hostname:0.0" and then whatever you run, anything that tries to create a new X window, will appear correctly.

EDIT: Obviously, once you've got it ironed out, you should probably put these in your shell init scripts, so you don't have to type them all the time.

Last edited by cavalier; 03-31-2005 at 02:22 PM.
 
Old 03-31-2005, 02:26 PM   #5
chbin
Member
 
Registered: Mar 2005
Distribution: slackware-current
Posts: 379

Original Poster
Rep: Reputation: 31
Quote:
"xhost +hostname"
I've seen that before and was thinking that could be one way.

I gotten it to work just by exporting the DISPLAY and XAUTHORITY without the "xhost +hostname". Is exporting the XAUTHORITY kinda of like using the brute force method. What is the difference between the two ways?
 
Old 03-31-2005, 02:28 PM   #6
cavalier
Member
 
Registered: Feb 2005
Location: Denver, CO
Distribution: Slack 12, tweaked just so (though I'm also a fan of Ubuntu)
Posts: 198
Blog Entries: 1

Rep: Reputation: 30
Quote:
Originally posted by chbin
I gotten it to work just by exporting the DISPLAY and XAUTHORITY without the "xhost +hostname"
I've never heard of this option before. When you say you exported XAUTHORITY, what command line did you use?
 
Old 03-31-2005, 02:37 PM   #7
chbin
Member
 
Registered: Mar 2005
Distribution: slackware-current
Posts: 379

Original Poster
Rep: Reputation: 31
Quote:
Originally posted by cavalier
I've never heard of this option before. When you say you exported XAUTHORITY, what command line did you use?
Yeah it's cool right. I've seen of "xhost +hostname" before I just never really had a need to use it until now and wasn't sure of it use.

First I start up an xterm and the user slack of course.

Second "su - root"

Third
export DISPLAY=":0,0"
export XAUTHORITY="/home/slack/.Xauthority

Fourth gvim.

Try it. It works.

The one way the user slack has to give me permission, which of course is me so no problem. The otherway I just take it by brute force. Hell I'm root and can do anything

What did I just do anyway

What is the difference between the two.
 
Old 03-31-2005, 02:42 PM   #8
cavalier
Member
 
Registered: Feb 2005
Location: Denver, CO
Distribution: Slack 12, tweaked just so (though I'm also a fan of Ubuntu)
Posts: 198
Blog Entries: 1

Rep: Reputation: 30
Interesting! I really never have seen that done before. It's very crafty, and as you said, as root, you can pretty much do whatever you want.

I guess the difference, honestly, is that with 'xhost +hostname' your user, slack, can give rights to people other than root to display things on his or her X session.

Also, if you put those commands in your .bashrc for root, for example, you'd always, as root, be trying to use the Xauthority file from the user slack, even if you logged in a root and ran X manually. Might be okay on your local desktop system, but if it were a server, there might well be times that you logged in as root, say from the console.
 
Old 03-31-2005, 04:27 PM   #9
chbin
Member
 
Registered: Mar 2005
Distribution: slackware-current
Posts: 379

Original Poster
Rep: Reputation: 31
Further investigation shows the the .Xauthority is the key file. It contains a mit-magic-cookie used to present itselft to the server. If a user present this right mit-magic-cookie then they can start X programs.

You don't even have to export XAUTHORITY, you could just copy the file into your own home directory and then start X programs up.

It seems that xhost tells the X server not to request the mit-magic-cookie to however you tell it to allow. Also there is xauth and xauth -merge which will just outright give the mit-magic-cookie to the specific user.

Funny how I was just took an educated guess that Xauthority was the key to everything and exported it into my root shell and it worked.


Also I couldn't use "xhost +localhost" becuase I have -nolisten tcp option. I hade to use "xhost local:", which gives permission over unix sockets only.
 
  


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
RHEL3 Mounting USB after reboot and between reboots: root and non-root users Luis Nunes Linux - Hardware 0 07-20-2005 08:32 AM
Root users Quiber SUSE / openSUSE 5 01-16-2005 12:50 AM
Different video drivers are loaded for root and non-root users triet Linux - Software 1 12-31-2004 02:20 PM
cannot su to root from users amuro_ray Linux - Newbie 4 06-13-2004 02:07 AM
Users other than root? ludeKing Linux - Newbie 4 07-25-2003 09:43 AM

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

All times are GMT -5. The time now is 06:11 PM.

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