LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Changing to root in konsole-cannot use kwrite (https://www.linuxquestions.org/questions/slackware-14/changing-to-root-in-konsole-cannot-use-kwrite-699120/)

exsencon 01-22-2009 08:31 AM

Changing to root in konsole-cannot use kwrite
 
Slackware newbie(and linux as well)
Dell Dimension 520 P4 3GHZ RAM 3GB HD 2*250GB Nvidia GeForce 7300LE
Installed:hd0 WinXP prof
hd1 Ubuntu/Kubuntu,LinuxMint,FedoraFC8,Suse10.3,Sabayon,Mandriva8,
Debian4,Slax6.03,Slackware12.2
Everything running fine with Kubuntu's grub bootloader in the MBR booting every system.
Slackware is running QK now(after a few glitches)but I still have a problem in the konsole.
When I go in as user and want to switch to root to change something using Kwrite or Kate I always get:(as example)

zeger@HOME:~$ su
Password:
root@HOME:/home/zeger# kwrite /etc/fstab
No protocol specified
kwrite: cannot connect to X server :0.0


So I have to switch user and go in as root and then it's OK.I think I must have done something wrong when adding the user but I have no clue.
Otherwise everything is running fine so far(as far as I can tell)

TSquaredF 01-22-2009 08:40 AM

No, you did not make any mistakes. In KDE, I edit the K menu (right click on the K menu to get that option), find KWrite under the System header, highlight & copy it, then immediately paste it back. Now you have two entries for KWrite. Select one of them & modify the "command" to add "kdesu " (that's kdesu[space]), without the double quotes, before the command. Also modify the "Name" so that it will be different from the original one, I usually use "KWrite - Root Privileges".
Regards,
Bill

David the H. 01-22-2009 09:09 AM

To add some more detail, the reason it doesn't work is because the root user doesn't have permission to connect to the current user's x-session, and also probably doesn't even have the DISPLAY shell variable set.

Using something like kdesu, or "su -" to log in transfers the the current user's environment settings to root so you can run gui programs. You can also set it manually with the following commands.

To give the local root access permission, run "xhost +localhost" as the user owning the x-session (notice that playing around with xhost can be a security risk).

To set the display variable, run "export DISPLAY=:0" as root (assuming the current display is 0, of course). Now that shell knows how to find the display to use.

To make the settings permanent you need to add them to your bash startup scripts.

PTrenholme 01-22-2009 09:15 AM

And the reason is that you "own" the connection from the server to the display, not "root". The X-server is complicated enough, and adding multiple owners for the same display in the mix, while possible, is not often a problem.

As t^2F said, you can create a menu entry so you own the display while letting root write to it.

Even simpler is to add yourself to /etc/sudoers. Then, instead of su -c 'kwrite <file>' (which won't work), you can do a sudo kwrite file (which will).

exsencon 01-22-2009 10:40 AM

OK First I tried to duplicate kwrite and that worked once,but after that and in the same konsole session it didn't work anymore. After I closed the konsole and restarted it even kdesu didn't work (same message)So I rebooted but no result.

Then I added myself to /etc/sudoers and did sudo kwrite /etc/fstab
It works and I can edit fstab but this is what I get:

zeger@HOME:~$ sudo kwrite /etc/fstab
Password:
Error: "/var/tmp/kdecache-zeger" is owned by uid 1000 instead of uid 0.
Error: "/tmp/kde-zeger" is owned by uid 1000 instead of uid 0.
zeger@HOME:~$

I understand that it is owned by me and not by root(uid O)correct?
Should I leave it like that or change something?

bgeddy 01-22-2009 01:30 PM

May I take it that you are booting up into run level 4 as booting into run level 3 and running "startx" to start KDE makes what you are trying to do work fine.

To be honest X isn't my field so I don't exactly know what the differences in starting it up my mean. I've been following this thread thinking "That's strange - I do this all the time with no problems." I start in run level 3 however.

exsencon 01-22-2009 02:45 PM

Booting up in runlevel 4 indeed which I find easier. I am not sure it has something to do with my problem though; I think it would have been the same with runlevel 3. Anyway it is fixed now.
Thank you all for the help!

bgeddy 01-22-2009 03:02 PM

Quote:

I think it would have been the same with runlevel 3
Nope - definitely doesn't happen when starting in run level 3 then running startx.

I wasn't making this up in my original post you know...

Anyway - glad it's fixed for you.

PTrenholme 01-22-2009 06:24 PM

Those "owned by 1000 not 0" are just warnings that you see because stderr is directed to your terminal. They're safely ignored. (Obviously, you're user number 1000 whilst root is 0.)

[edit]
Oh, a couple additional thoughts:

1) If you want to spawn your sudo session, you need to "activate" the sudo before you spawn the edit session.
2) If you don't want to see the messages, direct stderr to dev/null

Here's an illustration:
Code:

$ sudo echo
[sudo] password for Peter:

$ sudo kate /etc/fstab 2>/dev/null &
7139
$ disown
$


TSquaredF 01-23-2009 11:13 AM

exsencon:
Quote:

OK First I tried to duplicate kwrite and that worked once,but after that and in the same konsole session it didn't work anymore.
This doesn't sound like the instructions I posted. If you follow my post, you will have an entry in your K Menu right next to the original KWrite entry. Clicking on that entry will bring up a dialog box requesting your root password. After the password is entered, KWrite will start in root mode. Konsole is not involved at all.
Regards,
Bill

exsencon 01-24-2009 06:43 AM

Quote:

This doesn't sound like the instructions I posted. If you follow my post, you will have an entry in your K Menu right next to the original KWrite entry. Clicking on that entry will bring up a dialog box requesting your root password. After the password is entered, KWrite will start in root mode. Konsole is not involved at all.
My mistake. I misunderstood. Redid it the way you said and it works like a charm.Thanks

TSquaredF 01-24-2009 08:38 AM

Quote:

Redid it the way you said and it works like a charm.Thanks
Good, I'm glad it worked. I do the same thing with Dolphin for file management.
Regards,
Bill


All times are GMT -5. The time now is 08:34 AM.