sudo gedit X not working

How do I use sudo gedit [FILE] on openSUSE?

It pulls out this error:
isaak@unknown0015f26474fe:~> sudo gedit x

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

I’ve tried several possible solutions found on the internet but all without success.

  • EarthMind

gnomesu gedit
maybe?

Uwe

Thank you this works, but isn’t there a solution to fix this because I can’t even open my “Volume Control”, it says: connection failed.

I thought that perhaps these two errors could be connected.

Many thanks

I have found the cause of my last problem, this was because of a bug in Pulseaudio and so this question is answered. Thank you for your help.

After a system reboot gnomesu doesn’t work either, this error comes up:


Invalid MIT-MAGIC-COOKIE-1 keycannot open display: 
Run 'gedit --help' to see a full list of available command line options.

Is there any fix to get sudo gedit working?

  • EarthMind,

something’s wrong here, seems the apps cannot find the right display. Please try

xhost +localhost
sudo gedit

if the latter line doesn’t work:
sudo gedit --display=0:0

Uwe

The problem is that sudo isn’t keeping all of the necessary environment variables. Here’s the fix.

  1. sudo /usr/sbin/visudo
  2. There is a line like this:
Defaults env_keep = "LANG LC_ADDRESS LC_CTYPE LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE LC_TIME LC_ALL LANGUAGE LINGUAS XDG_SESSION_COOKIE"
  1. Add (press i to switch vi to insert mode)
DISPLAY XAUTHORITY

inside the quotes.

  1. Save and exit. (<Esc>:wq<Enter>)

Many thanks for your help, dmbrown00’s solution seem to have fixed it. I do hope that no more unexpected behavior will show up…

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Probably in the wrong industry for that… I would recommend
grave-digging to meet your desires. :slight_smile:

Good luck.

EarthMind wrote:
| Many thanks for your help, dmbrown00’s solution seem to have fixed it. I
| do hope that no more unexpected behavior will show up…
|
|
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIalIZ3s42bA80+9kRAnWfAJ4yoiZX3cTW0YLv49cNuCsOKQ7c6ACePUtT
hz6LjdcXDI1idq2TsURvbnY=
=QIkQ
-----END PGP SIGNATURE-----

ab@novell.com schrieb:
> Probably in the wrong industry for that… I would recommend
> grave-digging to meet your desires. :slight_smile:
>
> EarthMind wrote:
> | Many thanks for your help, dmbrown00’s solution seem to have fixed it. I
> | do hope that no more unexpected behavior will show up…

Even grave-digging comes with a risk of unearthing something unexpected.

SCNR
T.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hopefully not anybody’s (pun intended) “behavior”, though. If you
notice anything out of the ordinary behaving oddly you’re probably in a
movie. :slight_smile:

Good luck.

Tilman Schmidt wrote:
| ab@novell.com schrieb:
|> Probably in the wrong industry for that… I would recommend
|> grave-digging to meet your desires. :slight_smile:
|>
|> EarthMind wrote:
|> | Many thanks for your help, dmbrown00’s solution seem to have fixed
it. I
|> | do hope that no more unexpected behavior will show up…
|
| Even grave-digging comes with a risk of unearthing something unexpected.
|
| SCNR
| T.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIamLE3s42bA80+9kRAha4AJ9UdbMLzxYX5dD08IiBb3B02sdcZgCdHMXw
akStr3qsKjDgeZ3uddk9gTI=
=JJWf
-----END PGP SIGNATURE-----

Hi,
I’ve just loaded OpenSuSe 11 and have a similar problem. sudo gedit … results in “cannot open display”. The fixes listed here don’t seem to work for me.

vicmorgan wrote:

>
> Hi,
> I’ve just loaded OpenSuSe 11 and have a similar problem. sudo gedit
> … results in “cannot open display”. The fixes listed here don’t seem
> to work for me.
>
>

Due to increased security concerns, the Xorg server does not accept
connections from users other than whomever started it. This can be
changed.

To enable ‘sudo xxx’ to work:

sudo visudo

and edit the line starting with ‘Defaults env_keep = "LANG…’

add DISPLAY within the quotes

(there is a second occurrence of this line a few lines down, it’s commented
out and can be ignored)

This change causes the DISPLAY variable to be retained, and only needs to be
performed once.

You need to tell (ask?) the X server to accept connections from other users
(root in this case) by running:

xhost +

This disables access controls and allows any user to connect to the
currently running X server. No, not very secure, but if you’re the only
user on a machine, it’s acceptable. I tried with ‘xhost +localhost’ and
variants, no luck.

The ‘xhost +’ command must be executed at least once per session, so once
it’s run, you needn’t do it again unless you log out.

No, it’s not really a ‘simple fix’… but you’re trying to defeat
security… and with that in mind, it’s appropriate that it’s not simple.

A better solution (which I use) is to ‘su - root -c xxx’, which will prompt
you for root’s password, then run whatever command. This doesn’t subvert
security, and allows you to use the power of root to perform tasks.

you could of course alias that command:

alias xsudo=‘su - root -c’

and then

xsudo gedit xxx

would do what you desire.

Loni


L R Nix
lornix@lornix.com

L R Nix wrote:

> alias xsudo=‘su - root -c’

that is SO cool…THANKS…

but, it requires the xterm/konsole/whatever to remain open so long as the app is
running…is there a way to ‘detach’ the process…

AND, Alt+F2 (and type in) xsudo kate ~/Desktop/text.txt
doesn’t bring happiness, instead it rains “Could not run the specified command.”


DenverD (Linux Counter 282315)
A Texan in Denmark

DenverD wrote:

> L R Nix wrote:
>
>> alias xsudo=‘su - root -c’
>
> that is SO cool…THANKS…
>
> but, it requires the xterm/konsole/whatever to remain open so long as the
> app is running…is there a way to ‘detach’ the process…
>
> AND, Alt+F2 (and type in) xsudo kate ~/Desktop/text.txt
> doesn’t bring happiness, instead it rains “Could not run the specified
> command.”
>

Well, ‘alias’ is a bash command, best placed in bash.bashrc.local or the
profile.d subdir or even your own .bashrc or .alias…

Now, if you want to use something like that in the gui, try kdesu

ALT-F2

kdesu kate ~/Desktop/text.txt


L R Nix
lornix@lornix.com

On 08/08/2008 L R Nix wrote:
> Now, if you want to use something like that in the gui, try kdesu

Or gnomesu

Uwe

> Well, ‘alias’ is a bash command, best placed in bash.bashrc.local or the
> profile.d subdir or even your own .bashrc or .alias…

well, i did that (put it in /etc/bash.bashrc.local) and it runs just fine, but i
noted that if i use Konsole or xterm as my interface with bash to run

xsudo kate /etc/bash.bashrc.local

it launches and runs kate just fine as ROOT, but as previously
posted–apparently that that (Konsole) terminal MUST remain open for it now shows:

DenverD@Texan:~> xsudo kate /etc/bash.bashrc.local
Password:
kbuildsycoca running…

maybe i’d like to close that terminal, which is why i asked about how to
‘detach’ the process…perhaps i should have asked: once i’ve started kate as
root (using your xsudo) can i close the terminal?

> Now, if you want to use something like that in the gui, try kdesu
>
> ALT-F2
>
> kdesu kate ~/Desktop/text.txt

oh boy…i just learned that last week, and i’d already forgotten it!!
again.


DenverD (Linux Counter 282315)
A Texan in Denmark

I had luck with

xhost +local: