Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After changing hostname, gedit (and other X clients) don't open

After changing the hostname gedit is not working as expected, it shows error always in my root "No protocol specified"

** (gedit:23330): WARNING **: Could not open X display
No protocol specified
Cannot open display: 
Run 'gedit --help' to 
like image 262
Hari Haran Avatar asked Dec 16 '13 13:12

Hari Haran


1 Answers

It's not only gedit that is going to fail but actually all programs that use the X11 protocol to talk to the graphics server. X11 uses the Xauth protocol to authenticate connecting clients. When you login through some kind of a display manager, a MIT-MAGIC-COOKIE-1 authentication cookie is created and written into your ~/.Xauthority file. That file is read by X11 clients and the cookies available there are used to authenticate the connections.

The list of cookies in your ~/.Xauthority file can be displayed using xauth list:

$ xauth list
localhost:1012  MIT-MAGIC-COOKIE-1  bd988401cbf8xxxxxxxxxxxxxxxxxxxx
some.host.example.com/unix:1012  MIT-MAGIC-COOKIE-1  bd988401cbf8xxxxxxxxxxxxxxxxxxxx

If you change your host name, the X11 client library will no longer be able to find a matching cookie in the authentication database and the X11 server will reject the unauthenticated connection (unless configured otherwise).

What you can do is to add a matching cookie using xauth:

$ xauth add "$(hostname)/unix:0" MIT-MAGIC-COOKIE-1 bd988401cbf8xxxxxxxxxxxxxxxxxxxx

$(hostname) expands to the result of the hostname command and unix:0 corresponds to your DISPLAY environment variable being set to :0.0. If it is to another display number, e.g. :ddd.0, then you should change the added host entry accordingly to "($hostname)/unix:ddd". Note also that the value of the cookie being added should match the value of the existing one.

If you don't have a terminal emulator open at that time and you are unable to open one because of the authentication error, you could switch to the console (text mode), login there and execute the above command.

like image 189
Hristo Iliev Avatar answered Nov 15 '22 22:11

Hristo Iliev