问题
I try to execute the following line on ubuntu-server 14.04:
$ sudo gedit /usr/local/svn/passwd-team
and I get this error:
error: XDG_RUNTIME_DIR not set in the environment.
(gedit: 11805): Gtk-WARNING **: can not open display:
I Googled for help and saw that I had to write:
pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY gedit
Then I got the following message:
=== AUTHENTICATING FOR org.freedesktop.policykit.exec ===
Authenticating is needed to run '/usr/bin/env' as the super user
Authenticating as: student,,, (student)
Password:
no talloc stackframe at ../source3/param/loadparm.c:4864, leaking memory
=== AUTHENTICATING COMPLETE ===
error: XDG_RUNTIME_DIR not set in the environment.
7
(gedit: 11807): Gtk-WARNING **: can not open display:
Now what? I just want to edit passwd-team file. please guide me. Thanks a lot, Orian.
Edit: I used nano to edit that file, but the error is still there.
回答1:
I have faced similar issues when using gedit after i ssh into any other user.This may be due to missing permission.
Try the following :-
Open a new terminal from your current user. type in
sudo -i
This prompts for root password. Enter that and then you will be in able to access using root privilege.
Then Try Gedit the file you want to edit. If you need to do it using su for other user then after the above step, do
su <username>
Now Try gedit any file. Works for me.
回答2:
Run the following command:
pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY gedit /usr/local/svn/passwd-team
Enter your user account password in the password field.
Explanation:
When you run gedit as another user (in this case root) you're in fact starting the new minimal and isolated environment that doesn't carry on some "excessive" variables (among others variables responsible for injecting libraries or setting certain privileges). The command above causes to carry on user-specific X-server settings from the current session.
References:
- https://askubuntu.com/a/467994/185132
回答3:
I had the same problem. In my case I ran command below:
sudo visudo
In the file that opens I deleted the last line (env=http...) and I saved the file. Then everything worked as usual.
回答4:
Your explanation shows that you did not run the command with root privileges as the message appeared "Authenticating is needed to run '/usr/bin/env' as the super user"
Try to run it as
sudo pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY gedit
Then the screen asks for root password, type your password and you should be fine.
来源:https://stackoverflow.com/questions/27424115/xdg-runtime-dir-not-set-in-the-environment-and-pkexec-doesnt-work