2

I have a Debian 10 system with a desktop environment installed and running. When I open a terminal and try to run any GUI application , such as gedit, from the command line, it fails to open with the following messages:

# gedit
Unable to init server: Could not connect: Connection refused

(gedit:3575): Gtk-WARNING **: 12:26:48.311: cannot open display: 

This happens with any user, not just root.

I have tried running the following based on suggestions to no avail:

 export DISPLAY=:0
 export DISPLAY=:1
 export DISPLAY=:2
 export DISPLAY=:3
 export DISPLAY=:4
 export DISPLAY=:5
 export DISPLAY=:6




xhost +

Anyone have any idea whats wrong here?

EDIT:

If I run export DISPLAY=:0 as a normal user, then the normal user can run GUI programs from the command line, however whenever I try the same with root it fails with the messages:

No protocol specified
Unable to init server: Could not connect: Connection refused
No protocol specified
Unable to init server: Could not connect: Connection refused
No protocol specified
Unable to init server: Could not connect: Connection refused

(gedit:3609): Gtk-WARNING **: 12:33:16.307: cannot open display: :0

2 Answers 2

3

The display belongs to the user. So, if you want to allow another user to draw on it (think of it as a printer) you have to grant permissions.

There are many ways to do that, but the simplest is probably to open the graphic terminal and run:

$ xhost +

That will allow connections to the server from other users.

Then, from the other user you can run:

$ export DISPLAY=:0

It could be another display, such as :1 ...

If you want to avoid those two steps, you can ssh into the other user, with the -X flag (that forwards the display):

$ ssh -X -l other_user localhost
2
  • I have already tried xhost + to no avail. Oct 31, 2019 at 14:19
  • 1
    You have to do both things, in two different places. The xhost + as the normal user and then, from the other user's shell the export DISPLAY.... To check, just run xeyes. To be sure of the display you want to export for the second user, you can do echo $DISPLAY from the normal user's shell. Oct 31, 2019 at 14:36
-1

I just added switch -E after sudo command.

for example:

sudo -E gedit /etc/apt/sources.list
1
  • 1
    This doesn't answer the question posed by the original poster and doesn't explain how it solves the problem.
    – Thomas N
    Jun 21, 2021 at 18:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .