Monday, April 29, 2024
 Popular · Latest · Hot · Upcoming
18
rated 0 times [  18] [ 0]  / answers: 1 / hits: 87349  / 1 Year ago, thu, may 25, 2023, 8:25:13

When I run sudo gedit /path/to/some/random/file I get the following error



** (gedit:6262): WARNING **: Command line `dbus-launch --autolaunch=7f8731869e1c690b8205727e0000000a --binary-syntax --close-stderr' exited with non-zero exit status 1: Autolaunch error: X11 initialization failed.
Cannot open display:
Run 'gedit --help' to see a full list of available command line options.


Using gksudo doesn't help either which returns



Cannot open display: 
Run 'gedit --help' to see a full list of available command line options.


Any help guys. I need to have this capability to open files in Gedit as root.

I found this question with the same error but no solution Unable to launch gedit with sudo






EDIT

I found this post in Ubuntu Forums.

These are the instructions:




  1. echo $DISPLAY # you'll be needing this value 3 lines below

  2. sudo -i # or "su -" on older Slackwares

  3. xauth merge ~alien/.Xauthority # use your own username here instead of "alien"

  4. export DISPLAY=:0.0 # use the value of DISPLAY you've seen 3 lines before



On coming to command #3, I got this error

xauth: file /root/.Xauthority does not exist



Maybe this new info can shed more light.


More From » sudo

 Answers
5

Finally have found an answer. From this question Cannot connect to X Server when running app with sudo and especially this question Error when trying to run an app with sudo or gksudo.



I added the line Defaults env_keep+="DISPLAY" to the end of the visudo file at /etc/sudoers.



Yay, my sudo gedit is back!



EDIT



Got the same error again for sometime.



Did some more research, especially this answer https://askubuntu.com/a/137584/163331 and realized I had to add more options to the visudo file. Instead of Defaults env_keep+="DISPLAY", I used this line:



Defaults env_keep="XAUTHORIZATION XAUTHORITY TZ PS2 PS1 PATH LS_COLORS KRB5CCNAME HOSTNAME HOME DISPLAY COLORS"

[#27154] Thursday, May 25, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
exceeeelh

Total Points: 21
Total Questions: 109
Total Answers: 120

Location: Marshall Islands
Member since Wed, Jan 5, 2022
2 Years ago
exceeeelh questions
Sun, Nov 20, 22, 17:08, 1 Year ago
Sat, Jan 1, 22, 08:04, 2 Years ago
Wed, May 12, 21, 05:11, 3 Years ago
;