“xdg_runtime_dir not set in the environment” and pkexec doesn't work

谁说胖子不能爱 提交于 2019-12-08 02:13:19

问题


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:

  1. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!